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

    //判断浏览器是否支持 placeholder属性
        function isPlaceholder(){
            var input = document.createElement('input');
            return 'placeholder' in input;
        }
        if (!isPlaceholder()) {//不支持placeholder 用jquery来完成
            if(!isPlaceholder()){

                    $("input").not("input[type='password']").focus(function() {
                        var input = $(this);
                        if (input.val() == input.attr("placeholder")) {
                            input.val("");
                            input.removeClass("placeholder");
                        }
                    }).blur(function() {
                        var input = $(this);
                        if (input.val() == "" || input.val() == input.attr("placeholder")) {
                            input.addClass("placeholder");
                            input.val(input.attr("placeholder"));
                        }
                    }).blur().parents("form").submit(function() {
                        $(this).find("[placeholder]").each(function() {
                            var input = $(this);
                            if (input.val() == input.attr("placeholder")) {
                                input.val("");
                            }
                        });
                    });
                    //对password框的特殊处理1.创建一个text框 2获取焦点和失去焦点的时候切换
                    var pwdField    = $(".passShow");
                    var pwdVal      = pwdField.attr('placeholder');
                    pwdField.after('<input id="pwdPlaceholder" class="passtxt" type="text" value='+pwdVal+' autocomplete="off" />');
                    var pwdPlaceholder = $('#pwdPlaceholder');
                    pwdPlaceholder.show();
                    pwdField.hide();
                    pwdPlaceholder.focus(function(){
                        pwdPlaceholder.hide();
                        pwdField.show();
                        pwdField.focus();
                    });
                    pwdField.blur(function(){
                        if(pwdField.val() == '') {
                            pwdPlaceholder.show();
                            pwdField.hide();
                        }
                    });
                    
                }
        }

  • 相关阅读:
    1654. Minimum Jumps to Reach Home
    1129. Shortest Path with Alternating Colors
    1766. Tree of Coprimes
    1368. Minimum Cost to Make at Least One Valid Path in a Grid
    LeetCode 841 钥匙与房间
    LeetCode 268 缺失数字
    LeetCode 136 只出现一次的数字
    LeetCode 461 汉明距离
    LeetCode 557 反转字符串中的单词 III
    LeetCode 392 判断子序列
  • 原文地址:https://www.cnblogs.com/summer-qd/p/8287388.html
Copyright © 2011-2022 走看看