Mozilla display textarea selected text _javascript tips

Source: Internet
Author: User
Used to use Createrange to judge textarea selected text, this property although Mozilla also support, but put to textarea will not work.
It was later found that there were other ways to solve the Mozilla problem.
<pead> <title>textarea select</title> <meta http-equiv= "Content-type" content=; Charset=utf-8 "/> <meta name= keywords" content= "php,mysql,wap,javacript,xhtml,xml,wml,svg,,, mobile"/> ; script type= "Text/javascript" > <!--function DoS () {var Ta=document.getelementbyid ("Intextarea") if (document.selection) {//for IE var sel = Document.selection.createRange (); if (sel.text.length<1) {alert ("You do not select text--!"); return false} alert (Sel.text)} else{//for Firefox var startpos = Ta.selectionstart var endpos = Ta.selectionend if (startpos = = endpos) {alert ("You did not select text--!"); return false} alert (Ta.value.substring (Startpos,endpos))} ta.focus ()}//--> </script> </pead> <body> <div><input type=button onclick= "DoS ()" value= "Display selected text"/>< /div> <textarea id= "IntextaRea "cols=60 rows=10></textarea> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.