输入类型=“数字"上的选择开始/选择结束不再允许在 Chrome 中使用 [英] selectionStart/selectionEnd on input type="number" no longer allowed in Chrome

查看:18
本文介绍了输入类型=“数字"上的选择开始/选择结束不再允许在 Chrome 中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序在输入字段上使用SelectionStart来确定是否在按箭头键时自动将用户移动到下一个/上一个字段(即,选择在文本结束时,用户按下右箭头我们移动到下一个字段,否则)

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 现在阻止在 type="number" 的地方使用 selectionStart.它现在抛出异常:

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.

请参阅以下内容:

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" 输入字段中插入符号的位置?

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

推荐答案

仅允许使用文本/搜索、URL、电话和密码进行选择.对类型编号的输入禁用选择的可能原因是,在某些设备上,或在某些情况下(例如,当输入显示为简短的 list 时),可能没有插入符号.我发现的唯一解决方案是将输入类型更改为文本(使用适当的模式来限制输入).我仍在寻找一种无需更改输入类型的方法,并且会在我找到某些内容时发布更新.

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.

这篇关于输入类型=“数字"上的选择开始/选择结束不再允许在 Chrome 中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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