100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > placeholder在IE8中兼容性问题解决

placeholder在IE8中兼容性问题解决

时间:2020-02-05 21:08:03

相关推荐

placeholder在IE8中兼容性问题解决

placeholder是HTML5中的一个属性,可以在文本框中设置placeholder属性来显示一些提示性的文字,但对IE10以下的浏览器不支持,下面方法可以让placeholder能够使用在IE10以下的版本中。

第一种方法是在页面中添加下面一段脚本:

<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>

上面的方法不能支持password类型的文本框,网上找了些解决方法都不是很完美,最后发现jQuery的placeholder插件还不错,代码如下:

/oec/8946120 将placeholder.js文件引用到页面,页面中添加下面脚本:

<script type="text/javascript">$(function() {$('input, textarea').placeholder();});</script>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。