(function($) { /* 主要针对ie下input输入框的问题 */ 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", "")); } } } //判断是否支持placeholder function isplaceholer() { var input = document.createelement('input'); var textarea = document.createelement('textarea'); return "placeholder" in input; return "placeholder" in textarea; } //不支持的代码 if (!isplaceholer()) { $(function() { var form = $(this); var elements = form.find("input[type='text'][placeholder]"); var elements1 = form.find("textarea[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":"#a0a0a0","fontsize":"15px"}); } } }); elements1.each(function() { var s = $(this); var pvalue = s.attr("placeholder"); var svalue = s.val(); if (pvalue) { if (svalue == '') { s.val(pvalue).css({"color":"#a0a0a0","fontsize":"15px"}); } } }); 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":"#666","fontsize":"15px"}); } } }); elements1.focus(function() { var s = $(this); var pvalue = s.attr("placeholder"); var svalue = s.val(); if (svalue && pvalue) { if (svalue == pvalue) { s.val('').css({"color":"#666","fontsize":"15px"}); } } }); elements.blur(function() { var s = $(this); var pvalue = s.attr("placeholder"); var svalue = s.val(); if (!svalue) { s.val(pvalue).css({"color":"#a0a0a0","fontsize":"15px"}); } }); elements1.blur(function() { var s = $(this); var pvalue = s.attr("placeholder"); var svalue = s.val(); if (!svalue) { s.val(pvalue).css({"color":"#a0a0a0","fontsize":"15px"}); } }); var elementspass = form.find("input[type='password'][placeholder]"); elementspass.each(function(i) { var s = $(this); var pvalue = s.attr("placeholder"); var svalue = s.val(); if (pvalue) { if (svalue == '') { s.css({"color":"#999","fontsize":"15px"}); 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='placeholderfriendfocus(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);