码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-11-17 17:49:47      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:js

 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

标签:js

原文地址:http://blog.csdn.net/zerofine/article/details/41211997

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!