if语句检查多个布尔条件 [英] if statement checking for multiple boolean conditions

查看:115
本文介绍了if语句检查多个布尔条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个if语句,必须为每个条件调用函数checkEmpty().

I have a if statement that must call function checkEmpty() for every conditions.

function checkFormFilled(evt){
    var isFilled;
    if(checkEmpty('id1', 'class1') && //condition 1
       checkEmpty('id2', 'class2') && //condition 2
       checkEmpty('id3', 'class3') && //condition 3
       checkEmpty('id4', 'class4')){ //condition 4
       evt.preventDefault();
       isFilled = true;
    }
    return isFilled;
}

问题是当条件1为假(任何先前的条件为假)时,跳到evt.preventDefault()行,而没有调用其他随后的checkEmpty()函数.

The problem is when the condition 1 is false(any preceding condition is false), skips to the evt.preventDefault() line, doesn't get call other following checkEmpty() functions.

当所有条件都返回true时,我想调用evt.preventDefault().

I want to call evt.preventDefault() when all conditions return true.

还有其他方法可以使这项工作成功吗?

Is there other way around to make this work?

推荐答案

尝试使用逻辑运算符||

这篇关于if语句检查多个布尔条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆