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]