The range operation under IE is much stronger than that of Mozilla, where only the operation under IE is discussed.
Here are some features of cursor positioning:
1. The cursor does not change
Direct Obj.focus (), the cursor will return to the previous position, that is, the position is unchanged
2. The cursor is in the front
Copy Code code as follows:
var r = Obj.createtextrange ();
R.collapse ();
R.select ();
Use this method to make the cursor precede the input box
3. At the end of the cursor
Copy Code code as follows:
var r = Obj.createtextrange ();
R.collapse (FALSE);
R.select ();
Use this method to make the cursor stop at the end of the input box
4. Select the MoveStart or MoveEnd method for the range you want to use for some of the input box, and use the detailed method to refer to MSDN.
<script type= "Text/javascript" > Function sl (o, m, n) {var rt = O.createtextrange (); Rt.collapse (); Rt.select ();//cursor set the top var r = Document.selection.createRange (); R.collapse (FALSE); R.movestart ("character", m);//starting from M bit R.moveend ("character", n);//select N bit r.select (); } </script> <input name= "a" value= "123456789" ><input type=button value= "select" onclick= "SL (a,2,4)" >
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
5. To extend the movement and position of the cursor, this is a frequently asked question
<input name=a value= "123456789" > <input type=button value= "forward" onclick= "SetPos (a,-1)" > <input type= Button value= "Back" onclick= "SetPos (a,1)" > <input Type=button value= "position of current cursor" onclick= "GetPos (a)" > <script Type= "Text/javascript" > Function SetPos (obj,n) {obj.focus (); var r = Document.selection.createRange (); R.collapse (FALSE); R.move ("character", N); R.select (); }; function GetPos (obj) {obj.focus ();//cursor position unchanged var r = Document.selection.createRange (); R.collapse (FALSE); R.setendpoint ("Starttostart", Obj.createtextrange ()); alert (r.text.length); }; </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]