zoukankan      html  css  js  c++  java
  • 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插件还不错,代码如下:

    https://gist.github.com/oec2003/8946120
    将placeholder.js文件引用到页面,页面中添加下面脚本:
    <script type="text/javascript">
       $(function() {
            $('input, textarea').placeholder();
       });
    </script>
  • 相关阅读:
    python多线程多进程
    python单元测试unittest
    python学习笔记(一):python简介和入门
    今天的收获!!!
    Python django
    React router
    30分钟掌握ES6/ES2015核心内容
    webpack+React.js
    我喜欢的两个js类实现方式 现在再加上一个 极简主义法
    js实现的笛卡尔乘积-商品发布
  • 原文地址:https://www.cnblogs.com/whlives/p/3997812.html
Copyright © 2011-2022 走看看