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>

  • 相关阅读:
    回复结束
    UVA 10537
    RTP 记录 log 该机制
    python 时间处理
    照片总结---选择适当的NoSQL
    博客测试:博客系统i94web beta1.0 申请测试
    SQL随着子查询结果更新多个字段
    2机器学习实践笔记(k-最近邻)
    Android_Service组件详解
    Android多媒体分析-通过MediaStore获取Audio信息
  • 原文地址:https://www.cnblogs.com/xchlsl/p/4479840.html
Copyright © 2011-2022 走看看