This article mainly introduces how to obtain and set the Text Location of TextArea or input text box in JS, involving TextArea and input text operation skills, for more information about how to obtain and set the Text Location of TextArea or input text box in JS, see the following example. Share it with you for your reference. The specific implementation method is as follows:
Function getPos (el) {var range, textRange, duplicate el. focus () if (el. selectionStart) return el. selectionStart else if (document. selection) {// IE range = document. selection. createRange () if (range = null) return el. value. length textRange = el. createTextRange () duplicate = textRange. duplicate () textRange. moveToBookmark (range. getBookmark () duplicate. setEndPoint ('endstart', textRange) return duplicate. text. length} function setPos (el, pos) {var range el. focus () if (el. setSelectionRange) el. setSelectionRange (pos, pos) else if (el. createTextRange) {range. collapse (true) range. moveEnd ('character ', pos) range. moveStart ('character ', pos) range. select ()}}
I hope this article will help you design javascript programs.