Obtain the value of some selected items in input.

Source: Internet
Author: User

Obtain the selected value (for IE and Firefox) in the input. This example is very good.

The code is as follows: Copy code
Function Preview (obj)
{
Var TestWin = open ('');
TestWin.doc ument. write (obj. value );
}
Function copyCode (obj ){
Var rng = document. body. createTextRange ();
Rng. moveToElementText (obj );
Rng. scrollIntoView ();
Rng. select ();
Rng.exe cCommand ("Copy ");
Rng. collapse (false );
}
Function saveCode (obj ){
Var winname = window. open ('', '_ blank', 'Top = 10000 ');
Winname.doc ument. open ('text/html ', 'replace ');
Winname.doc ument. writeln (obj. value );
Winname.document.execcommand('saveas', '', 'homepage..htm ');
Winname. close ();
}
Function addBookmark (title, url ){
If (window. sidebar ){
Window. sidebar. addPanel (title, url ,"");
} Else if (document. all ){
Window. external. AddFavorite (url, title );
} Else if (window. opera & window. print ){
Return true;
}
}
<Script language = "javascript">
Var agt = navigator. userAgent. toLowerCase ();
Var ie = (agt. indexOf ("msie ")! =-1) & (agt. indexOf ("opera") =-1) & (agt. indexOf ("omniweb") =-1 ));
Function (){
Var myArea = document. getElementById ("s ");
Var selection;
If (! Ie ){
If (myArea. selectionStart! = Undefined ){
Selection = myArea. value. substr (myArea. selectionStart, myArea. selectionEnd-myArea. selectionStart );
}
} Else {
If (window. getSelection ){
Selection = window. getSelection ();
} Else if (document. getSelection ){
Selection = document. getSelection ();
} Else if (document. selection ){
Selection = document. selection. createRange (). text;
}
}
Alert (selection)
}
</Script>
<Input type = "text" value = "testtest" id = "s" name = "s"
Onmouseup = "javascript: a ()"/>

Run the code, copy the code, save the code, and add it to favorites.

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.