【发布时间】:2014-02-06 06:53:22
【问题描述】:
我们的应用程序在输入字段上使用SelectionStart来确定是否在按箭头键时自动将用户移动到下一个/上一个字段(即,选择在文本结束时,用户按下右箭头我们移动到下一个字段,否则)
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
有什么方法可以确定类型=“数字”的输入字段中插入符号的位置?
【问题讨论】:
-
嗯,没有更新。很好奇为什么要删除此功能。
-
另一种利用方式:如果你使用jquery-maskmoney插件输入类型号,也会出现同样的问题
-
能否将输入类型暂时更改为
text,检查插入符号的位置,然后将类型更改回number? -
@Stan 我认为交换类型不是很可行,尽管我还没有尝试过。
-
@Steven 它不起作用,selectionStart/End 总是返回为零:jsfiddle.net/Mottie/wMYKU