Java教程

密码验证框信息

本文主要是介绍密码验证框信息,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<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>
        div {
            width: 600px;
            margin: 100px auto;
        }

        .message {
            display: inline-block;
            font-size: 16px;
            color: #999;
            background: url(images/mess.png) no-repeat left center;
            padding-left: 20px;
            background-size: 20px;
        }

        .wrong {
            color: red;
            background: url(images/wrong.png) no-repeat left center;
            background-size: 20px;
        }

        .right {
            color: green;
            background: url(images/right.png) no-repeat left center;
            background-size: 20px;
        }
    </style>
</head>

<body>
    <div class="register">
        <input type="password" class="ipt">
        <p class="message">请输入6-16位密码</p>

        <script>
            // 事件源
            var ipt = document.querySelector('.ipt')
            var message = document.querySelector('.message')

            // 注册事件失去焦点
            ipt.onblur = function () {
                if (ipt.value.length < 6 || ipt.value.length > 16) {
                    message.innerHTML = '请输入6-16位密码'
                    message.className = 'message wrong'
                } else {
                    message.className = 'message right'
                    message.innerHTML = '输入正确'
                }
            }
        </script>

    </div>
</body>

 

这篇关于密码验证框信息的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!