我在 Chrome(版本 33 =>)和其他 webkit 浏览器中的简单“数字”输入字段中遇到以下错误
<input type="number" name="number">
Failed to execute 'setSelectionRange' on 'HTMLInputElement': The input element's type ('number') does not support selection.
我在 FF 和 IE (10=>) 中进行了测试并且运行良好
我在 chromium 项目中发现以下问题: https://code.google.com/p/chromium/issues/detail?id=346270
有什么想法吗?
谢谢!
最佳答案
是的,这是一个 webkit 错误,请尝试以下解决方案:
代码:
<div class="container">
<form role="form">
<div class="form-group">
<label for="tel">tel</label>
<input type="tel" class="form-control" id="tel" placeholder="tel"/>
</div>
</form>
</div>
<script>
$("#tel").mask("(99) 999-9999");
$("#tel").on("blur", function() {
var last = $(this).val().substr( $(this).val().indexOf("-") + 1 );
if( last.length == 3 ) {
var move = $(this).val().substr( $(this).val().indexOf("-") - 1, 1 );
var lastfour = move + last;
var first = $(this).val().substr( 0, 9 );
$(this).val( first + '-' + lastfour );
}
});
</script>
关于google-chrome - 无法在 'setSelectionRange' 上执行 'HTMLInputElement',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23012370/