Html5在ios上input标签自动填充内容移动光标至尾的方法

来源:互联网 发布:跨境电商软件 编辑:程序博客网 时间:2024/06/03 12:28

在做ionic框架下开发webapp,遇到了input框无法对于自动填充的内容做到聚焦时将光标自动移到末尾。在调研学习后,发现了以下方法,希望给大家有所帮助:

moveEnd: function(obj) {    obj.focus();    var len = obj.value.length;    if (document.selection) {        var sel = obj.createTextRange();        sel.moveStart('character', len);        sel.collapse();        sel.select();    } else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {        obj.selectionStart = obj.selectionEnd = len;    }},

在serves中实现以下方法,然后在controller.js中实现ng-click的绑定事件:

$scope.textAreaMoveEnd = function(){      console.log("点击事件触发");      commentService.moveEnd(document.getElementById('task-detail-comment-area'));    }

记得将input或者textarea的ID写为选择器里的id;

0 0
原创粉丝点击