首页 > Web开发 > 详细

angularjs Failed to read the 'selectionStart' property from 'HTMLInputElement':

时间:2016-06-06 11:55:22      阅读:1048      评论:0      收藏:0      [点我收藏+]

在找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':

原文:http://www.cnblogs.com/fsong/p/5563119.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!