Placeholder plugin and placeholder default color modification

Source: Internet
Author: User

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

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.