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>
  • 相关阅读:
    zookeeper C API
    《accelerated c++》第九章---设计类
    redis memcache 比较
    redis 学习记录
    php memcache 使用学习
    php新手需要注意的高效率编程
    linux常用命令
    curl和file_get_contents 区别以及各自的优劣
    php序列化问题
    socket编程 123
  • 原文地址:https://www.cnblogs.com/whlives/p/3997812.html
Copyright © 2011-2022 走看看