解决IE8、IE9 placeholder 不兼容的问题
作者:互联网
解决IE8、IE9 placeholder 不兼容的问题
html:
<input type="text" maxlength="30" name="username" class="input-txt" placeholder="请输入您的姓名">
js:
$("[placeholder]")
.focus(function() {
var input = $(this);
if (input.val() == input.attr("placeholder")) {
input.val("");
input.removeClass("placeholder");
}
})
.blur(function() {
var input = $(this);
if (input.val() == "" || input.val() == input.attr("placeholder")) {
input.addClass("placeholder");
input.val(input.attr("placeholder"));
}
})
.blur()
.parents("form")
.submit(function() {
$(this).find("[placeholder]").each(function() {
var input = $(this);
if (input.val() == input.attr("placeholder")) {
input.val("");
}
});
});
css:
input::-webkit-input-placeholder, textarea::-webkit-input-placeholder {
color: #666;
}
input:-moz-placeholder, textarea:-moz-placeholder {
color: #666;
}
input::-moz-placeholder, textarea::-moz-placeholder {
color: #666;
}
input:-ms-input-placeholder, textarea:-ms-input-placeholder {
color: #666;
}
标签:IE9,IE8,val,color,666,input,function,placeholder 来源: https://www.cnblogs.com/jlfw/p/12496060.html