The Createrange method of selection
Document.selection.createRange () returns the TextRange object based on the current text selection, or returns the Controlrange object based on the control selection.
With execcommand, it is useful in the HTML editor, such as: Text bold, italic, copy, paste, create hyperlinks, and so on.
Example one:
The code is as follows |
Copy Code |
<textarea cols=50 rows=15> Ha ha. We are all freshmen. We all come to help each other. So that we can progress, we can make money! </textarea> <input Type=button value= Select Word after clicking I look Onclick=alert (Document.selection.createRange (). Text) > </form> |
Say so much crap let's take a look at the position of the cursor in the input box instance
The code is as follows |
Copy Code |
function Getcursortposition (domobj) { var position = 0; if (document.selection) {//for IE Domobj.focus (); var sel = Document.selection.createRange (); Sel.movestart (' character ',-domobj.value.length); Position = Sel.text.length; else if (Domobj.selectionstart | | domobj.selectionstart = = ' 0 ') { Position = Domobj.selectionstart; } return position; } |
In JS get the current cursor position in the input box, you can use the following methods, compatible with IE, Chrome, Firefox and Safari
Related reference jquery/40412.htm >jquery get the cursor location http://www.111cn.net/wy/jquery/40412.htm