TextArea focus doesn't work in IE

Source: Internet
Author: User

Due to the fact that compatibility is not considered, today we are experiencing this problem:

<HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Document</title></Head><Body>    <textareaname=""ID=""cols= "+"rows= "Ten"readOnly=true>Sdfasdfadsfasdf</textarea>    <Scriptsrc= "Jquery-1.9.1.js"></Script>    <Scripttype= "Text/javascript">            $(function(){                 $('textarea'). On ('Click',function(){                         //$ (this). attr (' readOnly ', false);                        $( This). CSS ('Background-color','Transparent')                        var$textarea=$( This); /** SetTimeout (function () {$textarea. focus ();  }, 0); **/                        $( This). attr ('contenteditable',true); //$ (this). focus ();                 }); $('textarea'). On ('Blur',function(){                         $( This). attr ('readOnly',true); $( This). CSS ('Background-color','#666')                 });    }); </Script></Body></HTML>

The desired effect is a direct click to get the cursor and enter the characters in the textarea. But focus is not effective in IE. looking everywhere, or on the powerful stackoverflow found the answer.

The first: direct use of the Select () method without focus () but there is a serious problem with interactivity.

The second kind: StackOverflow above a solution is to use the above annotated settimeout event, I tried, not the effect. "A successful friend does not have the trouble to enlighten."

The Third kind: is still in StackOverflow, the above questioner last used is $ (this). attr (' contenteditable ', true); Contenteditable This property, this effect can be achieved. But only in IE effective, this special processing can be. This should be the best solution.

StackOverflow Links:

Http://stackoverflow.com/questions/9806910/textarea-is-not-editable-not-readonly-in-ie

Http://stackoverflow.com/questions/3764440/ie-readonly-textarea-problem

TextArea focus doesn't work in IE

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.