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>
  • 相关阅读:
    第二次会议
    第五次团队会议
    作业六:团队项目——编写项目的Spec
    DFD数据流程图
    第四次会议
    精通 VC++ 实效编程280例 03 控制栏
    1.窗体与界面设计工具栏设计
    HTML5开发 Local Storage 本地存储
    1.窗体与界面设计菜单应用实例
    精通 VC++ 实效编程280例 02 菜单和光标
  • 原文地址:https://www.cnblogs.com/liaohaihui/p/4177868.html
Copyright © 2011-2022 走看看