选择 iOS-输入由 javascript 创建时的键盘
Selecting iOS-Keyboard when input is created by javascript
通过 javascript 创建输入时,移动版 Safari 没有选择正确的键盘。对于 first input
,显示 decimalPad-keyboard is shown, but for second input
only the numbersAndPunctuation-keyboard。
我该如何解决这个问题?
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
说明:
一般情况下,"DOM attributes" for html节点通常写成驼峰式,如果你使用javascript!在 HTML 中,您将使用 "alllowercase" 版本。 "DON'T ASK WHY. ;-)"。但是更推荐在节点上使用 setAttribute()
方法,因为无论你写什么,它总是以 DOM 元素属性结束'
通过 javascript 创建输入时,移动版 Safari 没有选择正确的键盘。对于 first input
,显示 decimalPad-keyboard is shown, but for second input
only the numbersAndPunctuation-keyboard。
我该如何解决这个问题?
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
说明:
一般情况下,"DOM attributes" for html节点通常写成驼峰式,如果你使用javascript!在 HTML 中,您将使用 "alllowercase" 版本。 "DON'T ASK WHY. ;-)"。但是更推荐在节点上使用 setAttribute()
方法,因为无论你写什么,它总是以 DOM 元素属性结束'