Ie6\7\8 placeholder effect, support text box and Password box

Source: Internet
Author: User

(function ($) {
var placeholderfriend = {
Focus:function (s) {
s = $ (s). Hide (). Prev (). Show (). focus ();
var idvalue = s.attr ("id");
if (idvalue) {
S.ATTR ("id", Idvalue.replace ("Placeholderfriend", ""));
}
var clsvalue = s.attr ("class");
if (Clsvalue) {
S.attr ("Class", Clsvalue.replace ("Placeholderfriend", ""));
}
}
}

Determine if placeholder is supported
function Isplaceholer () {
var input = document.createelement (' input ');
Return "placeholder" in input;
}
Unsupported Code
if (!isplaceholer ()) {
$ (function () {

var form = $ (this);
var elements = form.find ("input[type= ' text '][placeholder]");
Elements.each (function () {
var s = $ (this);
var pValue = s.attr ("placeholder");
var svalue = S.val ();
if (PValue) {
if (svalue = = ") {
S.val (PValue). CSS (' color ', ' #E0E0E0 ');
}
}
});

Elements.focus (function () {
var s = $ (this);
var pValue = s.attr ("placeholder");
var svalue = S.val ();
if (svalue && pValue) {
if (svalue = = PValue) {
S.val ('). CSS (' color ', ' #E0E0E0 ');
}
}
});

Elements.blur (function () {
var s = $ (this);
var pValue = s.attr ("placeholder");
var svalue = S.val ();
if (!svalue) {
S.val (PValue);
}
});

var element_em = form.find ("input[type= ' email '][placeholder]");
Element_em.each (function () {
var s = $ (this);
var pValue = s.attr ("placeholder");
var svalue = S.val ();
if (PValue) {
if (svalue = = ") {
S.val (PValue). CSS (' color ', ' #E0E0E0 ');
}
}
});

Element_em.focus (function () {
var s = $ (this);
var pValue = s.attr ("placeholder");
var svalue = S.val ();
if (svalue && pValue) {
if (svalue = = PValue) {
S.val ('). CSS (' color ', ' #E0E0E0 ');
}
}
});

Element_em.blur (function () {
var s = $ (this);
var pValue = s.attr ("placeholder");
var svalue = S.val ();
if (!svalue) {
S.val (PValue);
}
});

var elementspass = form.find ("input[type= ' password '][placeholder]");
Elementspass.each (function (i) {
var s = $ (this);
var pValue = s.attr ("placeholder");
var svalue = S.val ();
S.val (svalue). CSS (' color ', ' #e0e0e0 ');
if (PValue) {
if (svalue = = ") {
var html = this.outerhtml | | "";
html = html.replace (/\s*type= ([' "])? Password\1/gi," Type=text placeholderfriend "). Replace (/\s* (?: value|on[a-z]+| Name) (= (['])? \s*\1)?/gi, ""). Replace (/\s*placeholderfriend/, "Placeholderfriend value= '" + pValue + "'" + "onfocus=" pl Aceholderfriendfocus (this); ' ");
var idvalue = s.attr ("id");
if (idvalue) {
S.ATTR ("id", Idvalue + "placeholderfriend");

}
var clsvalue = s.attr ("class");
if (Clsvalue) {
S.attr ("Class", Clsvalue + "placeholderfriend");
}
S.hide ();
S.after (HTML);
}
}
});

Elementspass.blur (function () {
var s = $ (this);
var svalue = S.val ();
if (svalue = = ") {
var idvalue = s.attr ("id");
if (idvalue) {
S.ATTR ("id", Idvalue + "placeholderfriend");
}
var clsvalue = s.attr ("class");
if (Clsvalue) {
S.attr ("Class", Clsvalue + "placeholderfriend");
}
S.hide (). Next (). Show ();
}
});

});
}
Window.placeholderfriendfocus = Placeholderfriend.focus;
}) (JQuery);

Ie6\7\8 placeholder effect, support text box and Password box

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.