简体   繁体   English

IF / else语句和运算符

[英]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. 这是应该的。

  1. check if password equals confirm_password 检查密码是否等于confirm_password
  2. check if fields or not empty 检查字段是否为空
  3. check if fields have the correct characters ( count start as count = 0 , foreach field that is correct it it goes count = count +1, in totaal it can get 8 but at 6 it still keeps submitting). 检查字段是否具有正确的字符(count从count = 0开始,对于正确的foreach字段,count = count +1,总和为8,但仍然为6)。

 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM