Html5的表单添加了许多给力的属性,其中输入框的placeholder便是很赞的属性!现代浏览器大多都支持这个属性,但IE8。。。。好吧,前端的童鞋们总会想出各种姿势对付IE的~_~
//使IE支持placeholder
if( !('placeholder' in document.createElement('input')) ){
$('input[placeholder]').each(function(){
var that = $(this),
text= that.attr('placeholder');
if(that.val() === ""){
that.val(text);
}
that.focus(function(){
if(that.val() === text){
that.val("");
}
}).blur(function(){
if(that.val() === ""){
that.val(text);
}
}).closest('form').submit(function(){
if(that.val() === text){
that.val('');
}
});
});
}
加上这一段代码,试试看,你的IE8是不是被你征服了~