ericblog1992
<!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: #aaa;
            font-size: 14px;
        }
        
        .right {
            color: green;
        }
        
        .wrong {
            color: red;
        }
    </style>
</head>

<body>
    <input type="text" class="uname"> <span>请输入用户名</span>
    <script>
        var reg = /^[a-zA-Z0-9_-]{6,16}$/;
        var uname = document.querySelector(\'.uname\');
        var span = document.querySelector(\'span\');
        uname.onblur = function() {
            if (reg.test(this.value)) {
                // console.log(\'yes\');
                span.className = \'right\';
                span.innerHTML = \'用户名输入正确\';
            } else {
                // console.log(\'no\');
                span.className = \'wrong\';
                span.innerHTML = \'用户名输入错误\';
            }
        }
    </script>
</body>

</html>

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-11-13
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
相关资源
相似解决方案