Document. selection. createRange method and instance

Source: Internet
Author: User

ExecCommand can be used in HTML editors, such as bold text, italic text, copying, pasting, and hyperlink creation.

<Pre class = "code" cols = 50 rows = 15> haha. We are new people. Everyone is here to help each other. So that we can make progress and make a lot of money! </Textarea> <input type = button value = select a word and click here to see onclick = alert (document. selection. createRange (). text)> </form>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

This is good.
<Body> <p> </p> <pre class = "code" name = "textfield" cols = "50" rows = "6"> is the current text field there is a piece of text, when you select a few words and click a button or link, a dialog box will pop up. The information in the dialog box is the text you selected. Which of the following statements can solve the problem? Please help me more !!! Thank you </textarea> </p> <input type = "button" value = "showSelection" onclick = "alert (document. selection. createRange (). text) "> <input type =" button "value =" showclear "onclick =" alert (document. selection. clear (). text) "> <input type =" button "value =" showtype "onclick =" alert (document. selection. type) "> </p> <pre class =" code "name =" textfield "cols =" 50 "rows =" 6 "onselect =" alert (document. selection. createRange (). Text) "> there is a piece of text in the text field. When you select a few words, click a button or link to bring up a dialog box, the information in the dialog box is the text you selected. Which of the following statements can solve this problem? Please help me more !!! Thank you </textarea> </p> </body>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]


Example 3: select text in Input
<Input type = 'text' id = 'test' name = 'test'> <input type = button onclick = 'test2 () 'value = 'test' name = 'test3'> after you select the content in textarea, add effect <input type = "button" value = "bold" onclick = "bold (); "/> <pre class =" code "name =" description "style =" width: 436px; height: 296px "> select me and click bold </textarea>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Example 4: javascript captures the plain text content in the selected webpage.
<Html> <pead> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "/> <title> mouse word acquisition </title> </pead> <body onmouseup =" getSel () "> the above Code can capture the plain Text content (excluding HTML tags) in the selected webpage. If you want to include html content, change document.selection.createrange().textto document.selection.createrange().html Text </body> </HTML>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

Related Article

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.