Perfect for IE compatible with the jquery implementation of the input placeholder attribute

Source: Internet
Author: User

Invoke the direct reference jquery with the following JS on the line, relative to most of the online example, this is a more perfect solution.

/** Ball to West Ravine * http://www.cnzj5u.com* 2014/11/26 12:12*/(function ($) {    //determine if placeholder is supported    functionIsplaceholer () {varinput = document.createelement ("Input"); return"Placeholder"inchinput; }    varPlaceholderfriend ={focus:function(s) {s=$ (s). Hide (). Prev (). Show (). focus (); }    }    //Unsupported Code    if(!Isplaceholer ()) {        $(function () {            varForm = $ ( This); varelements = Form.find ("Input[placeholder]"); Elements.each (function(i) {vars = $ ( This); varPValue = s.attr ("placeholder"); varsvalue =S.val (); if(pValue) {if(svalue = = "") {                        //DOM does not support type modification, you need to copy the Password box property, generate a new DOM                        varHTML = This. outerhtml | | ""; HTML=HTML. Replace (/\s*type= ([' "])? Password\1/gi," type=\ "text\" "). Replace (/\s*value= ([' "])? \s*\1?/gi," value=\ "" + PValue + "\" onfocus=\ "Phfrfocus (this); \" Style=\ "color: #a9a9a9; \" ");                        S.hide ();                    S.after (HTML);            }                }            }); Elements.blur (function () {                vars = $ ( This); varsvalue =S.val (); if(svalue = = ""{s.hide (). Next (). Show ();        }            });    }); } Window.phfrfocus=Placeholderfriend.focus;}) (jQuery);

Perfect for IE compatible with the jquery implementation of the input placeholder attribute

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.