zoukankan      html  css  js  c++  java
  • placeholder兼容ie9

    //placeholder兼容ie9
        function isPlaceholder(){
                var input = document.createElement('input');
                return 'placeholder' in input;
            }
            if (!isPlaceholder()) {//不支持placeholder 用jquery来完成
                $(document).ready(function() {
                    if(!isPlaceholder()){
                        $("input").not("input[type='password']").each(//把input绑定事件 排除password框
                                function(){
                                    if($(this).val()=="" && $(this).attr("placeholder")!=""){
                                        $(this).val($(this).attr("placeholder"));
                                        $(this).focus(function(){
                                            if($(this).val()==$(this).attr("placeholder")) $(this).val("");
                                        });
                                        $(this).blur(function(){
                                            if($(this).val()=="") $(this).val($(this).attr("placeholder"));
                                        });
                                    }
                                });
                        //对password框的特殊处理1.创建一个text框 2获取焦点和失去焦点的时候切换
                        $("input[type='password']").each(
                                function() {
                                    var pwdField    = $(this);
                                    var pwdVal      = pwdField.attr('placeholder');
                                    pwdField.after('<input  class="login-input" type="text" value='+pwdVal+' autocomplete="off" />');
                                    var pwdPlaceholder = $(this).siblings('.login-input');
                                    pwdPlaceholder.show();
                                    pwdField.hide();

                                    pwdPlaceholder.focus(function(){
                                        pwdPlaceholder.hide();
                                        pwdField.show();
                                        pwdField.focus();
                                    });

                                    pwdField.blur(function(){
                                        if(pwdField.val() == '') {
                                            pwdPlaceholder.show();
                                            pwdField.hide();
                                        }
                                    });
                                })
                    }
                });
            }

  • 相关阅读:
    Mysql有什么办法解决主备延迟的引起的过期读问题?
    jdk 8 交集 差集
    【立flag】_(:з」∠)_
    Linux基础01 虚拟机安装操作系统,网络类型(网口),网段, 分区,分配网络, KDUMP,网络配置, 快照, 克隆, Xshell优化, Linux历史
    oracle(enquences & latches )lock (oracle 锁大全)
    oracle 密码详解以及破解
    oracle 大表在线删除列操作(alter table table_name set unused )
    MacOs 使用 github 个人令牌(Personal access token)
    web网站在线安全扫描
    vue 实现快捷键录入功能
  • 原文地址:https://www.cnblogs.com/wugai/p/10904217.html
Copyright © 2011-2022 走看看