Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript未对无效的确认密码文本发出警报_Javascript_Forms_Passwords - Fatal编程技术网

JavaScript未对无效的确认密码文本发出警报

JavaScript未对无效的确认密码文本发出警报,javascript,forms,passwords,Javascript,Forms,Passwords,为了正确注册,用户需要输入两次密码,并且这两个文本框中的密码应该匹配。 但是,在使用此代码进行验证时,JavaScript不会显示警报对话框。 这里的pswrd和pswrd1是两个password类型的文本框 var message=""; var result=false; if(pswrd.value!== pswrd1.value) { message+="\nPasswords did not match"; result=false; } if(!result) {

为了正确注册,用户需要输入两次密码,并且这两个文本框中的密码应该匹配。 但是,在使用此代码进行验证时,JavaScript不会显示警报对话框。 这里的
pswrd
pswrd1
是两个
password
类型的文本框

var message="";
var result=false;
if(pswrd.value!== pswrd1.value)
{
    message+="\nPasswords did not match";
    result=false;
}
if(!result)
{
    alert(message);
}
试试这个

var message="";
var result=false;
if(pswrd.value!== pswrd1.value)
{
    message = "Passwords did not match";
    result=false;
}
else {
    result = true;
}
if(!result)
{
    alert(message);
}
试试这个代码

if(pswrd.value!== pswrd1.value)
{
  alert("Password does not matched!");
  return false;
}
希望得到以下帮助:)

如果(pswrd.value!=pswrd1.value)

上面粗体的文本应该是=和not==

==不是运算符,请使用==表示相等和=表示质量不合格