JavaScript code mainly used to select textarea text compatible with firefox and ie
The Code is as follows:
Function getSelectedText (){
Var selectedText;
Var textField = document. getElementById ('inputtextarea ');
If (window. getSelection) selectedText = getTextFieldSelection (textField); // getTextFieldSelection (document. getElementById ("inputTextArea "));
Else selectedText = document. selection. createRange (). text;
Alert (selectedText );
}
Function getTextFieldSelection (e ){
// Var oEvent = arguments. callee. caller. arguments [0];
If (e. selectionStart! = Undefined & e. selectionEnd! = Undefined)
Return e. value. substring (e. selectionStart, e. selectionEnd );
Else return "";
}
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN"> <HTML> <HEAD> <TITLE> JavaScript code compatible with textarea text in firefox _ www.jb51.net </TITLE> <meta name = "Generator" CONTENT = "EditPlus"> <meta name = "Author" CONTENT = ""> <meta name = "Keywords" CONTENT =" "> <meta name =" Description "CONTENT =" "> <script type =" text/javascript "> function getSelectedText () {var selectedText; var textField = document. getElementById (' InputTextarea '); if (window. getSelection) selectedText = getTextFieldSelection (textField); // getTextFieldSelection (document. getElementById ("inputTextArea"); else selectedText = document. selection. createRange (). text; alert (selectedText);} function getTextFieldSelection (e) {// var oEvent = arguments. callee. caller. arguments [0]; if (e. selectionStart! = Undefined & e. selectionEnd! = Undefined) return e. value. substring (e. selectionStart, e. selectionEnd); else return "";} script <style type = "text/css"> ul {list-style: none ;} </style> </HEAD> <BODY> <ul> <li> methods for selecting textarea text in firefox </li> <textarea id = "inputTextarea" rows = "6" cols = "50"/> never trust what I said, I have never been so brave and so strong. I keep vowed to tell stories honestly, but how strong is my desire to tell the truth, and how much interference I have. I sadly found that the truth cannot be restored at all. My memory is always changed by my emotions, and then I am teased and betrayed. It's hard to argue whether it's true or not. </Textarea> </li> <button onclick = "getSelectedText (); "> obtain the selected text segment </button> </li> </ul> </BODY> </HTML>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]