placeholder在IE8中兼容性问题解决
第一种方法是在页面中添加下面一段脚本:
<script type="text/javascript">
if( !('placeholder' in document.createElement('input')) ){
$('input[placeholder],textarea[placeholder]').each(function(){
var that = $(this),
text= that.attr('placeholder');
if(that.val()===""){
that.val(text).addClass('placeholder');
}
that.focus(function(){
if(that.val()===text){
that.val("").removeClass('placeholder');
}
})
.blur(function(){
if(that.val()===""){
that.val(text).addClass('placeholder');
}
})
.closest('form').submit(function(){
if(that.val() === text){
that.val('');
}
});
});
}
</script>
jQuery的placeholder插件很好
将placeholder.js文件引用到页面,页面中添加下面脚本:
<script type="text/javascript">
$(function() {
$('input, textarea').placeholder();
});
</script>