Our application uses selectionStart on input fields to determine whether to automatically move the user to the next/previous field when they press the arrow keys (ie, when the selection is at the end of the text and the user presses the right arrow我们移动到下一个字段,否则)
Chrome 现在会阻止在 type="number"处使用 selectionStart。 它现在抛出异常:
Failed to read the 'selectionStart' property from 'HTMLInputElement': The input element's type ('number') does not support selection.
请参阅以下内容:
https://codereview.chromium.org/100433008/#ps60001
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#do-not-apply
有什么方法可以确定插入符号在 type="number"的输入字段中的位置?
最佳答案
Selection is only permitted with text/search, URL, tel and password .对于类型 number 的输入,选择被禁用的可能原因是在某些设备上,或在某些情况下(例如,当输入显示为简短的 list
时),可能没有插入符号。我找到的唯一解决方案是将输入类型更改为文本(使用适当的模式来限制输入)。我仍在寻找一种不更改输入类型的方法,并会在找到内容时发布更新。
关于javascript - Chrome 不再允许输入类型 ="number"上的 selectionStart/selectionEnd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21177489/