首页 > 其他 > 详细

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

时间:2014-11-17 17:47:03      阅读:236      评论: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://blog.csdn.net/zerofine/article/details/41211997

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