Examples of js createRange and createTextRange usage

Source: Internet
Author: User

1. return text and htmlText of createTextRange
<Input type = "button" onclick = "test ()" value = "text"> <input type = "button" onclick = "test1 ()" value = "htmlText">
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

2. Obtain the selected text in the specified text box: only the first text box is returned.
<Input id = "inp1" type = "text" value = "1234567890"> <input id = "inp2" type = "text" value = "9876543210"> <input type = ""button" onclick = "test () "value =" OK ">
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

3. reverse search of page text
Abababababababa <input value = "reverse lookup a" onclick = myfindtext ("a") type = "button">
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

4. Focus the control and put the cursor at the end
<Input type = "text" value = "http://jb51.net" onfocus = "setFocus ()">
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

5. Obtain the cursor position in the text box.
<Input type = "text" id = "txt1" value = "1234567890"> <input type = "button" value = "Get cursor position" onclick = getPos (txt1)>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

6. Control the cursor position in the input box
<Input type = "text" id = "text1" value = "1234567890"> <select onchange = "setPos (this. selectedIndex) "> <option value =" 0 "> 0 </option> <option value =" 1 "> 1 </option> <option value =" 2 "> 2 </option> <option value = "3"> 3 </option> <option value = "4"> 4 </option> <option value = "5"> 5 </option> <option value = "6"> 6 </option> <option value = "7"> 7 </option> </select>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

7. Select a text section in the text box
<Input type = "text" id = "text1" value = "1234567890"> <select onchange = "sel (text1, this. value) "> <option value =" 0 "> 0 </option> <option value =" 1 "> 1 </option> <option value =" 2 "> 2 </option> <option value = "3"> 3 </option> <option value = "4"> 4 </option> <option value = "5"> 5 </option> <option value = "6"> 6 </option> <option value = "7"> 7 </option> </select>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

8. control the movement of the cursor in the text box
<Input type = "button" value = "<" onclick = go (-1)> <input id = "demo" value = "here is the text"> <input type = "button" value = ">" onclick = go (1)> /[html] 9. Position of the cursor: [html] <body> click textarea <pre class = "code" onclick = doit () rows = "6" cols = "33"> sdfsdfsdfsdfsdfsdf
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
10. Use the mouse to select some fonts. The selected fonts will be automatically pasted in textarea.
<Html> test this. I am skanso. <pre class = "code" name = pp> </textarea> </ptml>
[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.