placeholder 不支持ie8

//判断是否存在placeholder属性

function placeholder(el){
function isPlaceHolder(){
var textarea = document.createElement("textarea");
return "placeholder" in textarea;
}

//在不支持placeHolder属性的情况下
if(isPlaceHolder() == false && !('placeholder' in document.createElement('textarea'))){
$('textarea[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);
}
})
})
}
}

posted @ 2018-10-30 00:08  sidekick-boy  阅读(152)  评论(0)    收藏  举报