1$.fn.placeholder =function(){2$( This). each (function(i, EL) {3 varSelf =$ (EL);4 if($.browser.msie &&!) ("Placeholder"inch$ ("<input/>") [0])) {5 if(Self.attr ("Data-placeholder") | |! Self.attr ("placeholder")){6 return;7 }8Self.attr ("Data-placeholder",true);9 varthat = $ ("<div/>");Ten varParent =self.parent (); One if(Parent.css ("position")!== "Absolute" &&parent.css ("position")!== "fixed"){ AParent.css ("position", "relative"); - } - That.css ({ the' Left ': Self.offset (). Left-parent.offset (). Left + parseint (self.css ("borderLeftWidth")), -"Top": Self.offset (). Top-parent.offset (). Top + parseint (self.css ("borderTopWidth")), -"Width": Self.width (), -"Height": Self.height (), +"Lineheight": Self.css ("Lineheight"), -"FontSize": Self.css ("FontSize"), +"Paddingleft": Self.css ("Paddingleft"), A"Paddingtop": Self.css ("Paddingtop"), at"Textindent": Self.css ("Textindent"), -"Position": "Absolute", -"Color": "#666669", -"Outline": "None!important", -"Border": "None!important", -"BackgroundColor": "Transparent", in"Cursor": "Text" - }); toThat.html (self.attr ("placeholder")); + Parent.append (that); -That.on ("click",function() { theSelf[0].focus (); * }); $ functionShowplaceholder () {Panax Notoginseng if(Self.val () = = = "") { - that.show () the}Else { + that.hide (); A } the } +Self.on ("Input PropertyChange", Showplaceholder); - Showplaceholder (); $ } $ }); - }; - the$(function() { -$ ("[placeholder]"). PlaceHolder (); Wuyi});
Change the default color code for placeholder as follows:
::-moz-placeholder {color:red;} //ff::-webkit-input-placeholder{color:red;} //chrome,safari:-ms-input-placeholder{color:red;} //ie10
The placeholder plugin does not handle the browser that supports its own placeholder, and the lower version creates a div in the same class. (Remember to introduce jquery)
Placeholder plugin and placeholder default color modification