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]);
时间: 2024-10-27 13:47:37