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();
                        }
                    });
                    
                }
        }

  • 相关阅读:
    2020蓝桥杯模拟赛(一)
    自己整理的瀑布流+滚动加载图片的例子
    .NET如何发送格式化的文本内容
    Bootstrap学习笔记(3)--表格表单图片
    BootStap学习笔记(2)
    BootStap学习笔记(1)
    Oracle性能优化
    Maven+spring+springMVC+mybatis+Junit+Log4j配置个人总结
    C#指针和寻址运算
    Linq to XML
  • 原文地址:https://www.cnblogs.com/summer-qd/p/8287388.html
Copyright © 2011-2022 走看看