(function () { //对于ie10以下版本placeholder的兼容性调整 $(function () { $("input[type='text'],textarea").bind({ "focus": function () { var placeholderval = $(this).attr("placeholder"); var realval = $(this).val(); if ($.trim(realval) == placeholderval) { $(this).val(""); } }, "blur": function () { var placeholderval = $(this).attr("placeholder"); var realval = $(this).val(); if ($.trim(realval) == "") { $(this).val(placeholderval); } } }); $("input[type='text'],textarea").each(function (i, n) { if ($(this).val() == "") $(this).val($(this).attr("placeholder")); }); $("input[type='password']").bind({ "focus": function () { var placeholderval = $(this).attr("placeholder"); var realval = $(this).val(); if ($.trim(realval) == placeholderval) { var copy_this = $(this).clone(true, true); $(copy_this).attr("type", "password"); $(copy_this).insertafter($(this)); $(this).remove(); $(copy_this).val(""); $(copy_this).focus(); } }, "blur": function () { var placeholderval = $(this).attr("placeholder"); var realval = $(this).val(); if ($.trim(realval) == "") { var copy_this = $(this).clone(true, true); $(copy_this).attr("type", "text"); $(copy_this).insertafter($(this)); $(this).remove(); $(copy_this).val(placeholderval); } } }); $("input[type='password']").each(function (i, n) { var placeholderval = $(this).attr("placeholder"); var copy_this = $(this).clone(true, true); $(copy_this).attr("type", "text"); $(copy_this).insertafter($(this)); $(this).remove(); $(copy_this).val(placeholderval); }); }); })();