Created
March 6, 2017 02:40
-
-
Save iHaPBoy/3ed0e94ccdd3a0337b00169fcc3d113f to your computer and use it in GitHub Desktop.
JavaScript 移动光标到文本末尾
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function moveEnd(obj) { | |
obj.focus(); | |
var len = obj.value.length; | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment