首页 > 其他 > 详细

textarea光标移到末尾兼容ie,ffchrome

时间:2017-04-12 11:30:57      阅读:253      评论:0      收藏:0      [点我收藏+]
 function moveEnd(obj){
        obj.focus();
        var len = obj.value.length;
        if (document.selection) {//ie识别
            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;//ff和chrome
        }


    }


仅仅用调用方法。传进去对象就可以,jquery演示样例:moveEnd($(".moreComment  textarea")[0]);

textarea光标移到末尾兼容ie,ffchrome

原文:http://www.cnblogs.com/gccbuaa/p/6697969.html

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