javascript - javascript 创建输入时选择 iOS 键盘
问题描述
通过 javascript 创建输入时,移动 safari 不会选择正确的键盘。first input
显示小数点键盘,但second input
仅显示数字和标点键盘。
我怎样才能解决这个问题?
let myInput = document.createElement('input');
myInput.id = 'second';
myInput.type = 'number';
myInput.min = '0';
myInput.step = 'any';
myInput.inputmode = 'decimal';
document.getElementById('here').appendChild(myInput);
first input: <input id='first' type='number' min='0' step='any' inputmode='decimal'>
<div id='here'>second input: </div>
解决方案
而不是使用:
myInput.inputmode = 'decimal';
用这个:
myInput.setAttribute('inputmode','decimal');
或者
myInput.inputMode = 'decimal'; // uppercase M
说明:一般来说,如果你使用javascript ,html 节点的“DOM 属性”通常是用驼峰命名的!在HTML中,您将使用“alllowercase”版本。“不要问为什么。;-)”。但更推荐在节点上使用方法,因为无论你写什么,这总是以 DOM 元素属性结束setAttribute()
推荐阅读
- php - 请帮助我关于限制
- 在这个 php sneppet 上
- pytest-html - pytest-html 插件报告,列出取消选择的测试
- kotlin - 如何让应用程序从 Reactor Kafka 请求超时导致的 RetriableCommitFailedException 中自我恢复?
- javascript - 是否可以在上传到服务器之前更改为图像的字节大小或宽度和高度?
- ios - 尝试从 tableView 加载图像时,Swift View Controller 空白
- python - 加载图像的更快方法?
- amazon-web-services - AWS EC2 启动模板资源标签是否优先于 Autoscaling Group (ASG) 标签?
- jenkins - 管道后期构建失败并出现错误 java.io.NotSerializableException: hudson.tasks.junit.TestResultAction
- javascript - 在 PHP 中更改下拉菜单时执行函数
- xml - 我如何通过读取 XSD 文件知道我的 XML 命名空间应该是什么?