The Range operation in IE is much better than that in Mozilla. Here we only discuss the operation in IE.
Here we will introduce several features of cursor positioning:
1. The cursor remains unchanged
Directly obj. focus (), the cursor returns the previous position, that is, the position remains unchanged.
2. cursor at the beginning
Copy codeThe Code is as follows: var r = obj. createTextRange ();
R. collapse ();
R. select ();
This method can make the cursor at the beginning of the input box
3. The cursor is at the end
Copy codeThe Code is as follows: var r = obj. createTextRange ();
R. collapse (false );
R. select ();
This method can be used to place the cursor at the end of the input box.
4. Select some content in the input box and use the Range moveStart or moveEnd method. For detailed usage, see MSDN.
<Input name = "a" value = "123456789"> <input type = "button" value = "select" onclick = "sl (a, 2, 4)">
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
5. Let's look at 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 =" backward "onclick =" setpos (a, 1) "> <input type =" button "value =" current cursor position "onclick =" getpos (a) ">
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]