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