selectionStart / selectionEnd on input type =“number”不再允许在Chrome中使用 [英] selectionStart/selectionEnd on input type="number" no longer allowed in Chrome

查看:403
本文介绍了selectionStart / selectionEnd on input type =“number”不再允许在Chrome中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序在输入字段上使用selectionStart来确定当用户按下箭头键时是否自动将用户移动到下一个/上一个字段(即,当选择位于文本的末尾并且用户按下右箭头时我们会移至下一个字段,否则)

Chrome现在会阻止selectionStart在type =number处使用。
现在抛出异常:

 无法从'HTMLInputElement'中读取'selectionStart'属性:输入元素类型('数字')不支持选择。 

请参阅以下内容:

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中确定插入符的位置的方法?解析方案

选择只允许使用文本/搜索,URL,电话和密码。对于类型编号的输入禁用选择的可能原因是在某些设备上或在某些情况下(例如,当输入已被显示为短列表 ),可能没有插入符号。我找到的唯一解决方案是将输入类型更改为文本(使用适当的模式来限制输入)。我仍然在寻找一种方法来处理,而无需更改输入类型,并在发现问题时发布更新。


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 we move to the next field, otherwise)

Chrome now prevents selectionStart from being used where type="number". It now throws the exception:

Failed to read the 'selectionStart' property from 'HTMLInputElement': The input element's type ('number') does not support selection.

See following:

https://codereview.chromium.org/100433008/#ps60001

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#do-not-apply

Is there any way to determine the location of the caret in an input field of type="number"?

解决方案

Selection is only permitted with text/search, URL, tel and password. The likely reason that selection has been disabled for inputs of type number is that on some devices, or under some circumstances (e.g., when the input has been is presented as a short list), there might not be a caret. The only solution I have found was to change the input type to text (with appropriate pattern to restrict input). I am still looking for a way to do with without changing the input type and will post an update when I find something.

这篇关于selectionStart / selectionEnd on input type =“number”不再允许在Chrome中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆