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

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>让ie也兼容placeholder</title>
    <style>
        input::-moz-placeholder{ color:#00f;}
        ::-webkit-input-placeholder{ color:#00f;}
    </style>
    <script src="../../js/jquery-1.7.2.js"></script>
    <script>
    $(function(){
        function placeHolder(wrapDom){
            var support='placeholder' in document.createElement('input');
                if(!support){
                    var $pass=$("input[type=password]"),
                    passL=$pass.length;
                    if(passL){
                        $pass.hide().parent().append("<input type='text' value='请输入密码' class='pwdtext'/>");
                        $(".pwdtext").focus(function(){
                            $(this).hide().prev("input").show().focus();
                        })
                    }
                    wrapDom.find('[placeholder]').focus(function() {
                        var input = $(this);
                        if(input.val() == input.attr('placeholder')) {
                            input.val('');
                        }                    
                    }).blur(function() {
                        var input = $(this);
                        if(/^password/.test(input.attr("id"))){
                            if(!input.val()) {
                                input.hide().next("input").show();
                            }
                        }
                        if(input.val() == '' || input.val() == input.attr('placeholder')) {
                           input.val(input.attr('placeholder'));
                        }
                    }).blur();
                };
        }
        placeHolder($("#test"));    
    })
    </script>
    </head>

    <body>
    <form action="" method="post" id="test">
        <input type="text" name="username" id="username"  placeholder="用户名" />
        <input type="password" name="password" id="password" placeholder="密码"/>
    </form>
    </body>
    </html>

  • 相关阅读:
    查看进程在CPU和内存占用的命令
    Android studio 启动模拟器出现 VT-x is disabled in BIOS 以及 /dev/kvm is not found
    awk命令过滤tomcat的访日日志中IP地址
    windows 2008R2系统程序运行提示无法定位程序输入点ucrtbase.terminate
    k8s中yaml文件pod的语法(转)
    etcd和redis的比较和日常使用场景
    从gitlab或者github采用git clone和download zip的区别
    记录一次mysql查询速度慢造成CPU使用率很高情况
    USG防火墙DHCP设置保留IP地址
    让docker容器开机启动
  • 原文地址:https://www.cnblogs.com/xchlsl/p/4479840.html
Copyright © 2011-2022 走看看