Improved "perfect for IE compatible input placeholder property of jquery implementation" imperfect

Source: Internet
Author: User

The code in the jquery implementation of the perfect make IE compatible with Input placeholder property is IE9 in the following browsers because the browser below IE9 interprets the label of input differently.

For example, the following text boxes are interpreted:

<input id= "iTXt" class= "Itext" type= "text" title= "This is a text box" value= "point I enter Content" tabindex= "1" maxlength= ">

  

IE7:

  

IE8:

  

IE9:

<input id= "iTXt" class= "Itext" title= "This is a text box" tabindex= "1" maxlength= "" value= "point I enter Content" type= "text" >

  

For such a different explanation, I just want to say ie to die. But from the beginning of IE9, it seems that IE is desperately to do not die, this is how much let us these bitter coder some gratified.

And the "perfect let IE compatible with input placeholder attributes of the jquery implementation" is not perfect because our regular can not verify the differences caused by these ie.

Here's the perfect solution:

/** Ball to West Ravine * http://www.cnzj5u.com* 2014/11/26 12:12*/(function ($) {//Determine if placeholder function Isplaceholer () is supported () {        var input = document.createelement ("input");    Return "placeholder" in input;        } var placeholderfriend = {Focus:function (s) {s = $ (s). Hide (). Prev (). Show (). focus ();            }}//Unsupported code if (!isplaceholer ()) {$ (function () {var form = $ (this);            var elements = Form.find ("Input[placeholder]");                Elements.each (function () {var s = $ (this);                var pValue = s.attr ("placeholder");                var svalue = S.val ();                        if (pValue) {if (svalue = = "") {//dom does not support type modification, you need to copy the Password box property to generate a new DOM var newinputstr = s.prop (' outerhtml ') | |                        ""; Newinputstr = Newinputstr.replace (/type[""]*=[""]*password[""]*/g, "type=\" text\ ""). Repla CE (/type[""]*=["" "]*[']\s*password[" "]*["] [""]*/g "type=\" text\ ""). Replace (/type[""]*=[""]*["\" "]pass                        word["]*[" \ "" "]/g," type=\ "text\" ");                        Newinput = $ (NEWINPUTSTR); Newinput.attr ("Value", S.attr ("placeholder")). CSS ("Color", "#a9a9a9"). focus (function () {PLACEH                        Olderfriendfocus (this);                        });                        S.hide ();                    S.after (Newinput);            }                }            });                Elements.blur (function () {var s = $ (this);                var svalue = S.val ();                if (svalue = = "") {S.hide (). Next (). Show ();        }            });    }); } Window.placeholderfriendfocus = Placeholderfriend.focus;}) (JQuery);

  

Improved "perfect for IE compatible input placeholder property of jquery implementation" imperfect

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.