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>

  • 相关阅读:
    电力项目七--js控制文字内容过长的显示和文本字数的显示
    电力项目六--运行监控设计
    Maven开发系统
    SSH电力项目一 搭建Hibernate框架
    网站添加用户风险测评
    tomcat中文配置
    Tomcat映射路径的配置方法
    java中计算时间差
    NSTimer+倒计时功能实现
    设置UITextView光标从起始位置开始
  • 原文地址:https://www.cnblogs.com/xchlsl/p/4479840.html
Copyright © 2011-2022 走看看