javascript - Chrome 不再允许输入类型 ="number"上的 selectionStart/selectionEnd

标签 javascript google-chrome

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/

相关文章:

javascript - Aurelia JSPM install -y 在窗口上不起作用

javascript - 链接到动态 anchor

javascript - HTML5 FileReader API 内存问题

node.js - 检测 Google Chrome 页面预取

javascript - 尝试使用 Node.js 抓取 YouTube 主页时出现空数组

javascript - chrome 中的程序化书签

javascript - 将字符串换行超过 2 行 - SVG

javascript - 如何在 wordpress 中使用 php 函数(在 functions.php 中)返回的值分配一个 javascript 变量(在页面上)

Javascript 闭包在绑定(bind)到事件时表现不同

ios - 在 Chrome 上模拟 iPhone X