Source code:
Copy codeThe Code is as follows:
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Meta name = "Author" content = "">
<Title> content filtering </title>
<Script type = 'text/javascript '>
Function getPositions (){
Var el = document. getElementById ('shaixua ');
Var startPosition = 0; // start position of the selected text
Var endPosition = 0; // end position of the selected text
If (document. selection ){
// IE
Var range = document. selection. createRange (); // create a range object
Var drange = range. duplicate (); // clone an object
Drange. moveToElementText (el); // copy range
Drange. setEndPoint ('endtoend', range );
StartPosition = drange. text. length-range. text. length;
EndPosition = startPosition + range. text. length;
}
Else if (window. getSelection ){
// Firefox, Chrome, Safari etc
StartPosition = el. selectionStart;
EndPosition = el. selectionEnd;
}
Return {
"Start": startPosition,
"End": endPosition
}
}
// @ Todo get the selected text in textarea
Function getshaixuan (){
Var position = getPositions ();
Var start = position. start; // start position
Var end = position. end; // end position
Var text = document. getElementById ('shaixuany'). value;
Var selectText = text. substr (start, (end-start); // In textarea, the selected text
// Alert (selectText );
Var textBox1 = document. getElementById ("canjia ");
TextBox1.innerText = textBox1.value + selectText;
}
//]>
</Script>
<Title> copying an element </title>
<Style type = "text/css">
<! --
Body {font-size: 18px}
P {border-style: none}
. P1 {background-color: # FFFFFF; margin-top: 60px; margin-bottom: 3px; margin-left: 200px ;}
. P2 {background-color: # FFFFFF; margin-top: 2px; margin-bottom: 3px; margin-left: 150px ;}
. P3 {background-color: # FFFFFF; margin-top: 1px; margin-bottom: 3px; position: absolute; left: 550px; top: 60px}
. P4 {background-color: # FFFFFF; margin-top: 1px; margin-bottom: 3px; position: absolute; left: 500px; top: 85px}
. P5 {background-color: # FFFFFF; margin-top: 1px; margin-bottom: 3px; position: absolute; left: margin PX; top: margin PX}
-->
</Style>
</Head>
<Body>
<P class = "p1"> Filter list </p>
<Textarea id = "shaixuan" name = "check" cols = "23" rows = "15" class = "p2"> </textarea>
<Div class = "p3"> participants </div>
<Textarea id = "canjia" name = "canjia" cols = "23" rows = "15" class = "p4"> </textarea>
<Input type = "button" value = "content replication" class = "p5" onclick = "getshaixuan ();">
<! -- </Textarea> <button onclick = "getshaixuan ()"> get content </button> -->
</Body>
</Html>
Effect: