html5兼容IE placeholder问题
来源:互联网 发布:java style标签 编辑:程序博客网 时间:2024/06/05 06:45
最近遇到了用html5写的留言板,提示信息用的placeholder,但是在IE6/IE7/IE8/IE9下面不出效果,原因是H5的placeholder属性在IE下没有被支持。
解决方法:
用jQuery写js解决,代码如下
需要先引入jQuery
<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>
记得这段代码需要在dom文档加载完毕后执行,不然不出效果。
- html5兼容IE placeholder问题
- html5 placeholder ie版本兼容
- Html5的placeholder属性(IE兼容)
- IE兼容实现HTML5的placeholder
- html5的placeholder属性(IE如何兼容placeholder属性)
- IE兼容html5的placeholder属性(IE如何兼容placeholder属性)
- Html5 placeholder 兼容(不支持的浏览器ie)
- 兼容IE的placeholder
- placeholder兼容ie
- placeholder 兼容IE
- placeholder兼容ie
- 使IE兼容placeholder属性
- IE兼容-placeholder的方法
- placeholder兼容ie和password
- 解决HTML5布局,兼容IE问题
- 解决IE不支持HTML5表单属性placeholder的问题
- placeholder IE失效问题
- html5兼容ie
- 平衡二叉树
- linux常用命令
- Linux apache 添加 mod_rewrite模块
- LeetCode题解:Maximum Subarray
- iOS - App内使用代码退出程序
- html5兼容IE placeholder问题
- 昨天临摹了网店的首页。以后可以自己装修用所以格外用心了些
- 进程间通信
- MacOS安装与运行MongoDB
- Linux下查看文件内容的命令
- JAVA SDutOJ 题目收录
- 软件测试(一) 近期的一次debug的经历
- 内存管理与垃圾回收2之内存溢出的三种情况及解决办法
- Uva10562——Undraw the Trees