Created
September 28, 2013 07:21
-
-
Save xyqfer/6739475 to your computer and use it in GitHub Desktop.
文本框中选择指定长度的文本
This file contains hidden or 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 selectText(textbox, startIndex, stopIndex) { | |
| if (textbox.setSelectionRange) { | |
| textbox.setSelectionRange(startIndex, stopIndex); | |
| } else if (textbox.createTextRange) { | |
| var range = textbox.createTextRange(); | |
| range.collapse(true); | |
| range.moveStart("character", startIndex); | |
| range.moveEnd("character", stopIndex - startIndex); | |
| range.select(); | |
| } | |
| textbox.focus(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment