Cursor Operation Summary

Source: Internet
Author: User

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.