[英]IF/ else statements and Operators
I working on a form but I have some troubles with the last if statement ( it's not working. 我正在处理表单,但是最后一个if语句有一些麻烦(它不起作用。
count
is global and start as 0
, for each field with the correct character filled in this will happen: count = count+1;
count
是全局的,并且从0
开始,对于填充了正确字符的每个字段,都会发生: count = count+1;
but if I clicked submit and leave 2 fields with not the correct character 但是,如果我单击“提交”并留下2个字段且字符不正确
( that should be count = 6
) it doesn't give me an alert but skips it (应该是
count = 6
),它不会给我警报,但会跳过它
this is how it should be. 这是应该的。
function validateForm() { var fields = ["voornaam", "achternaam", "Email", "Wachtwoord", "Herhaal_Wachtwoord", "Straatnaam", "Huisnummer", "Postcode", "Woonplaats", "Telefoonummer"]; if (pass1.value !== pass2.value) { alert("Wachtwoord komen niet overeen"); return false; } var l = fields.length; var fieldname; for (i = 0; i < l; i++) { fieldname = fields[i]; if (document.forms["register"][fieldname].value === "") { alert(fieldname + " can not be empty"); return false; } } if (count < 8) { alert("iets is niet goed ingevuld"); return false; } }
You have returned the false
boolean before you have given the alert prompt! 在给出警告提示之前,您已经返回了
false
布尔值! Just change the last if
statement like this: 只需更改最后一个
if
语句,如下所示:
if (count < 8) {
alert("iets is niet goed ingevuld");
return false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.