<script>
var stamp = document.getElementById("btn");
//验证用户名
function named(){
var name=document.getElementById("username").value;
if(name.length < 11){
document.getElementById("b4").innerHTML="<font size='2' color='red'>昵称长度不够";
}else{
document.getElementById("b4").innerHTML="<font size='4' color='lime'>√";
}
}
function id(){
var name=document.getElementById("pid").value;
if(name.length < 11){
document.getElementById("b1").innerHTML="<font size='2' color='red'>账号长度不够";
}else{
document.getElementById("b1").innerHTML="<font size='4' color='lime'>√";
}
}

//验证密码
function demo(){
var name = document.getElementById("passwd1").value;
if(name.length < 6){
document.getElementById("b2").innerHTML="<font size='2' color='red'>密码长度不够";
}else{
document.getElementById("b2").innerHTML="<font size='4' color='lime'>√";
}
}

//验证确认密码
function mima(){
var passwd1=document.getElementById("passwd1").value;
var  passwd2=document.getElementById("passwd2").value;
if(passwd1 == passwd2){
document.getElementById("b3").innerHTML="<font size='4' color='lime'>√";
stamp.disabled=false;;
}else{
document.getElementById("b3").innerHTML="<font size='2' color='red'>两次密码不一致";
stamp.disabled=true;
}
}
</script>

解决方案 »

  1.   

    你得把html代码晒出来啊,光看js代码不一定能看出问题的
      

  2.   

    首先你的username和pid值获取到了吗还是undefined
      

  3.   

    用alert或者console看看你js代码获取的用户名和密码是不是对的。
      

  4.   

    alter啊,前端断点一点点的跑嘛
      

  5.   

    <!DOCTYPE html>
    <html lang="en"><head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>Document</title>
    </head><body>
      昵称:<input type="text" id="username" onblur="named()">
      <div id="b4"></div>
      账号:<input type="text" id="pid" onblur="pid()">
      <div id="b1"></div>
      密码:<input type="password" id="passwd1" onblur="demo()">
      <div id="b2"></div>
      密码:<input type="password" id="passwd2" onblur="mima()">
      <div id="b3"></div>
      <button id="btn">提交</button>
      <script>
        function $(id) {
          return document.getElementById(id)
        }
        let name = $('username')
        let nick = $('pid')
        let pwd1 = $('passwd1')
        let pwd2 = $('passwd2')
        let b1 = $('b1')
        let b2 = $('b2')
        let b3 = $('b3')
        let b4 = $('b4')
        let btn = $('btn')
        btn.disabled = true // 初始设置不能点击
        //验证用户名
        function named() {
          if (name.value.length < 11) {
            b4.innerHTML = "<font size='2' color='red'>昵称长度不够";
          } else {
            b4.innerHTML = "<font size='4' color='lime'>√";
          }
        }    function pid() {
          if (nick.value.length < 11) {
            b1.innerHTML = "<font size='2' color='red'>账号长度不够";
          } else {
            b1.innerHTML = "<font size='4' color='lime'>√";
          }
        }    //验证密码
        function demo() {
          if (pwd1.value.length < 6) {
            b2.innerHTML = "<font size='2' color='red'>密码长度不够";
          } else {
            b2.innerHTML = "<font size='4' color='lime'>√";
          }
        }    //验证确认密码
        function mima() {
          if(pwd2.value!=="") {
            if (pwd1.value == pwd2.value) {
              b3.innerHTML = "<font size='4' color='lime'>√";
              btn.disabled = false;
            } else {
              b3.innerHTML = "<font size='2' color='red'>两次密码不一致";
              btn.disabled = true;
            }
          } else {
            b3.innerHTML = "<font size='2' color='red'>再次密码长度不够";
            btn.disabled = true;
          }
        }
      </script>
      </script>
    </body>
     完善一下密码验证代码,你账户名用id作为方法名,这个是关键字,应该是有问题的
      

  6.   


    function mima(){
    var passwd1=document.getElementById("passwd1").value;    //我记得获取值,是 .val() 吧? 
    var  passwd2=document.getElementById("passwd2").value;
    if(passwd1 == passwd2){     //这里我还是觉得用eq比较好,可能是个人固执的认为==用来比较非常量的内存地址吧。
    document.getElementById("b3").innerHTML="<font size='4' color='lime'>√"; //这里不需要 </font> 结束符吗?
    stamp.disabled=false;;
    }else{
    document.getElementById("b3").innerHTML="<font size='2' color='red'>两次密码不一致"; //同上,</font>
    stamp.disabled=true;
    }
    }