将光标放到文本末尾
function moveEnd(obj){ obj.focus(); var len = obj.value.length; //IE 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; } }
Seleciton介绍:http://www.cnblogs.com/surahe/articles/5981847.html