zoukankan      html  css  js  c++  java
  • 让IE低版本浏览器也支持placeholder属性

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>让IE低版本浏览器也支持placeholder属性</title>
        <script type="text/javascript"  src="http://ajax.microsoft.com/ajax/jquery/jquery-1.11.1.min.js"></script>
        <script type="text/javascript">
            $(function () {
                if (/MSIEs(d+)/.test(navigator.userAgent) && navigator.userAgent.match(/MSIEs(d+)/)[1] < 10) {
                    $('[placeholder]').each(function () {
                        var pla = $(this).attr('placeholder');
                        $(this).focus(function () {
                            if ($(this).val() == pla) {
                                $(this).val('');
                            }
                        }).blur(function () {
                            if ($(this).val() == '') {
                                $(this).val(pla);
                            }
                        });
                        $(this).trigger('blur');//此处利用blur事件,为了业务需求。防止页面上查询后,文本框需要保留搜索的关键被placeholder代替
                    });
                }
            });
        </script>
    </head>
    <body>
        <input type="text" placeholder="请输入关键字" />
    </body>
    </html>
  • 相关阅读:
    hdu6055(求正方形个数)
    树状数组模板(改点求段 / 该段求点 / 改段求段)
    poj2763(lca / RMQ + 线段树)
    poj3728(lca / tarjan离线)
    JDK8-废弃永久代(PermGen)迎来元空间(Metaspace)
    JVM垃圾回收机制
    虚拟机字节码执行引擎
    Java中程序初始化的顺序
    Java中ClassLoader浅析.
    Python中的self
  • 原文地址:https://www.cnblogs.com/liaohaihui/p/4177868.html
Copyright © 2011-2022 走看看