2023-07-13T16:17:53.png

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

        .bg{
            background-color: yellow;
        }
        .aa{
            display:block;
        }
        .ab{
            display:block;
        }
        span{ 
            display:none;float:left;
        }
        input{float:left;}
    </style>
</head>
<body>
    
        <input type="text" id="name" >
    <span id="yhm">请输入3至6位数的用户名</span>
    <br><br>
        <input type="text" id="pw" >
    <span id="mm"> 请输入6至8位数的密码</span>
    <br><br>
        <input type="button" id="btn" value="提交">
    <script>
        var btn = document.getElementById("btn");
        var username = document.getElementById('name');
        var pw = document.getElementById('pw');
        var yhm = document.getElementById("yhm");
        var mm = document.getElementById("mm");

        btn.onclick = function(){
            if(username.value.length < 3 || username.value.length > 6){
                username.className = "bg";
                yhm.className = "aa";
            }else{
                username.className = "";
                yhm.className = "";
            }
        
         if(pw.value.length < 6 || pw.value.length > 8){
                pw.className = "bg";
                mm.className = "ab";
            }else{
                pw.className = "";
                mm.className = "";
            }
        };

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