Js、Jquery密码输入框的密码显示与隐藏

                                            Js、Jquery密码输入框的密码显示与隐藏
                
1、基本理解:
    鼠标左键按下去时,把输入框的属性改为text;鼠标左键松开时,把输入框的属性改为password
2、html代码:
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>js,jquery密码输入框的密码显示与隐藏</title>
        <style type="text/css">
            /**样式*/
            .seePasswordClass{color:#4DAAF6}
            .seePasswordClass:hover{color:red;text-decoration:underline;cursor:pointer}
        </style>
    </head>
    <body>
        密码:<input type="password" id="passwordId" value="20180413test"/>
        &nbsp;<span class='seePasswordClass' οnclick="seePasswordMethod(this,1)">js查看</span>
        &nbsp;<span class='seePasswordClass' οnclick="seePasswordMethod(this,2)">jquery查看</span>
    </body>
</html>
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
    /**
     * @todo 鼠标[按住/松开] => [显示/隐藏] 密码
     * @param obj 当前点击对象
     * @param type 类型:1 js点击;2 jquery点击
    */
    function seePasswordMethod(obj, type){
        if( type == 1 ){    //js查看
            var pass=document.getElementById("passwordId")  
            obj.οnmοusedοwn=function(){  
                pass.type="text"  
            };  
            obj.οnmοuseup=function(){  
            pass.type="password"  
        }  
        }else if( type ==  2 ){    //jquery查看
            $(obj).mousedown(function(){  
                $('#passwordId').attr("type", "text");  
            });  
            $(obj).mouseup(function(){  
                $('#passwordId').attr("type", "password");  
            });
        }
    }
</script>
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值