密码的显示隐藏、判断密码位数的小案例

密码的显示隐藏

!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #pass{
            width: 250px;
            height: 20px;
            border: none;
            outline: none;
            border-bottom: 1px solid #999;
        }
        #span{
            display: inline-block;
            cursor: pointer;
            width: 20px;
            height: 20px; 
            background: url("images/close.png");
            background-size: 20px;
            margin-left: -25px;
        }
    </style>
</head>
<body>
    <input type="password" id="pass">
    <span id="span"></span>
    <script>
        var int=document.getElementById("pass");
        var t=true;
        var yan=document.getElementById("span");
        yan.onclick=function(){
            if(t){
                int.type="text";
                t=false;
                yan.style.backgroundImage='url("images/open.png")';
            }else{
                int.type="password";
                t=true;
                yan.style.backgroundImage='url("images/close.png")';
            }
        }
    </script>
</body>
</html>

判断密码的长度

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        span{
            color: #666;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <input type="password" id="int"><span id="span">请输入6-16的密码</span>
    <script>
        var int=document.getElementById("int");
        var span=document.getElementById("span");
        int.onblur=function(){
            if(int.value.length < 6 || int.value.length > 16){
                span.innerHTML="密码该是6-16位的";
                span.style.cssText="color:red;";
            }else{
                span.innerHTML="密码正确";
                span.style.cssText="color:green;";
            }
        }
    </script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值