Gets the value of the partially selected (selected) in input

Source: Internet
Author: User
Select| selected

  To get the value of the partial check (selected) in input (for IE and Firefox), this is a good example to share.

<textarea id="code"><script language= "javascript" >var agt=navigator.useragent.tolowercase (); var ie = (Agt.indexof ("MSIE")!=- 1) && (Agt.indexof ("opera") = = 1) && (Agt.indexof ("omniweb") = = 1); function A () {var myarea = Document.g Etelementbyid ("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"/></textarea>
Run code Copy Code Save Code Collect this page

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.