javascript错误。密码和确认密码具有相同的值,但仍显示错误

javascript错误。密码和确认密码具有相同的值,但仍显示错误,javascript,Javascript,显示错误甚至密码匹配 if (confirmpassword != password ) { document.getElementById('error').innerHTML="*Password not match!"; return false; }; 找不到此错误。这是截图 你没有提供太多的信息,但我想你是在一个关键事件中或在改变evernt时打电话来的。希望这有帮助 if (confirmpassword != password ) { document.getE

显示错误甚至密码匹配

if (confirmpassword != password ) {
  document.getElementById('error').innerHTML="*Password not match!";
  return false;
};
找不到此错误。这是截图


你没有提供太多的信息,但我想你是在一个关键事件中或在改变evernt时打电话来的。希望这有帮助

if (confirmpassword != password ) {
     document.getElementById('error').innerHTML="*Password not match!";
     return false;
}else{
     document.getElementById('error').innerHTML="";
}

您应该使用以下代码:

if (confirmpassword !== password ) {
  document.getElementById('error').innerHTML="*Password not match!";
  return false;
} else {
  document.getElementById('error').innerHTML="";
  return true;
};

因此,如果此条件为passes,请确保输入字符不相同。

这里有一个解释,因为我看到您不熟悉JavaScript术语和逻辑

在JavaScript,有========,考虑:

==等于

==等值和等类型

意思是:

if (confirmpassword != password ) {
            document.getElementById('error').innerHTML="*Password not match!";
            return false;
        };
将检查confirmpassword和password是否不等于相同的值

将检查confirmpassword和password是否不等于相同的值和类型


请发一封信。问题中的代码不足,无法提供答案。请使用!==安装=我怀疑confirmpassword和password是元素,而不是字符串,但鉴于提供的代码数量,无法知道。请用编辑框编辑您的问题。
if (confirmpassword !== password ) {
            document.getElementById('error').innerHTML="*Password not match!";
            return false;
        };