JS implements the function example of selecting the specified text content in the specified HTML Element Object,
This example describes how to use JavaScript to specify the text content in the specified HTML Element Object. We will share this with you for your reference. The details are as follows:
This function is useful and can be used flexibly! The main functions are as follows:
// Specify part of the function selectSomeText (obj, start, end) {if (document. selection) {if (obj. tagName = 'textea ') {var I = obj. value. indexOf ("\ r", 0); while (I! =-1 & I <end) {end --; if (I <start) {start --;} I = obj. value. indexOf ("\ r", I + 1);} var range = obj. createTextRange (); range. collapse (true); range. moveStart ('character ', start); if (end! = Undefined) {range. moveEnd ('character ', end-start);} range. select ();} else {obj. selectionStart = start; var sel_end = end = undefined? Start: end; obj. selectionEnd = Math. min (sel_end, obj. value. length); obj. focus ();}}
And then, For example:
SelectSomeText (document. getElementById ('jiu _ textarea '), 2nd) // select to 8 words in jiu_textarea!
Complete example:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Run the following command: