一个简单的js密码验证记录

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        form>p>input{
            color: #999;
        }
        #ipt{
            color: #333;
        }
        span{
            color: #999;
        }
    

    </style>
</head>
<body>
    <form action="">
        <h2>世纪佳缘登录</h2>
        <p>账号:<input type="text" name="" id="text" value="请输入您的账号" placeholder></p>
        <p>密码:<input type="text" name="" id="ipt2" value="请输入您的密码" placeholder> <span>请输入6-16位的密码</span></p>
        <input type="button" value="提交" id="submit">
        <input type="reset" value="重置">
    </form>
    <script>
        var input = document.getElementById("text");
        var ipt = document.getElementById("ipt2");
        var span=document.querySelector("span");
        var submit=document.getElementById("submit")
        input.onfocus=function(){
            if(input.value!=""){
                this.value=""
            }
            this.style.color="#333"

        }
         input.onblur=function(){
            this.style.color="#999"
            if(this.value==""){
                this.value="请输入您的账号"
            }
        }

        ipt.onfocus=function(){
            if(input.value!=""){
                this.value=""
            }
            this.type="password"
            this.style.color="#333"
        }

            ipt.onblur = function(){


            if(this.value.length<6 || this.value.length>16){
                span.style.color="red"
                span.innerHTML="请出入正确的密码"
                
            }
            else{
                
                span.style.color="green"
                span.innerHTML="您输入正确"

            }
            
            
        }
        submit.onclick = function(){
            if(input.value=='123456'&&ipt.value=='123456')
            {
                alert('密码正确')
            }
            else{
                alert('密码错误,请输入正确的密码')
            }
        }

           

    </script>
</body>
</html>

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值