angularjs Failed to read the 'selectionStart' property from 'HTMLInputElement':(示例代码
Posted wakasann
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了angularjs Failed to read the 'selectionStart' property from 'HTMLInputElement':(示例代码相关的知识,希望对你有一定的参考价值。
在找angularjs input(type=‘number‘)在获取焦点的时候,文本框内容选中效果,参考了:Select text on input focus,我直接复制他的code之后,在ionic中报"Uncaught InvalidStateError: Failed to read the ‘selectionStart‘ property from ‘HTMLInputElement‘: The input element‘s type (‘number‘) does not support selection.",
尝试了
---
this.setSelectionRange(0, 9999)
---
this.selectionStart = 0;
this.selectionEnd = 999;
上面两个选中文本,我在webapp中测试的时候,需要每次双击之后才会有效果,我尝试用jQuery的select()方法来达到这个效果,再ionic编译的apk中测试可用之后,觉得这是我目前的解决方法。
directive方法代码
.directive(‘selectOnClick‘, function ($window) { return { restrict: ‘A‘, link: function (scope, element, attrs) { element.on(‘click‘, function () { if (!$window.getSelection().toString()) { // Required for mobile Safari $(this).select(); } }); } }; })
input使用这个directive(指令)像:
<input type="text" value="test" select-on-click />
再android app中,使用type="number"也可以工作。
以上是关于angularjs Failed to read the 'selectionStart' property from 'HTMLInputElement':(示例代码的主要内容,如果未能解决你的问题,请参考以下文章
安卓failed to copy to sdcard:read-only file system
Failed to read candidate component class
Failed to read candidate component class: URL [];
Failed to read artifact descriptor for xxx:jar