angularjs 1 Failed to read the 'selectionStart' property from 'HTMLInputElement':
2016-06-06 11:11
603 查看
在找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方法代码
input使用这个directive(指令)像:
再android app中,使用type="number"也可以工作。
尝试了
---
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的语法介绍
- AngularJS: 使用Scope时的6个陷阱
- angularjs 日志
- AngularJS 使用元素与事件指令
- AngularJS 使用绑定和模板指令
- AngularJS(4)——ionic 框架下实现 Localstorage本地存储
- AngularJS之代码风格36条建议【一】(九)
- angularjs 设置全局变量的7种方法
- 【angularjs 自学系列】1.过滤器
- AngularJs(八) 过滤器filter创建
- 在AngularJS的controller外部直接获取$scope
- AngularJs开发——控制器间的通信
- Angular2入门——(3)模板的逻辑控制
- [POJ 2836] Rectangular Covering (状压DP)
- 关于angularJS绑定数据时自动转义html标签
- AngularJS 模块化
- angular tab切换
- Backbone与Angular的比较
- angularjs2 学习笔记(六) Form
- AngularJS 学习之路(1)