Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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_Jquery - Fatal编程技术网

Javascript 如何在条件下检查两个变量?

Javascript 如何在条件下检查两个变量?,javascript,jquery,Javascript,Jquery,如果我不检查供应商和客户,我想隐藏表格 非常感谢。当前您的if子句如下所示: $('.supplier').on('click', function(){ var supplier = $('.supplier').is(":checked"); var customer = $('.customer').is(":checked"); // if both is unchecked, hide the table if( sup

如果我不检查供应商和客户,我想隐藏表格


非常感谢。

当前您的if子句如下所示:

$('.supplier').on('click', function(){
        var supplier = $('.supplier').is(":checked");
        var customer = $('.customer').is(":checked");

        // if both is unchecked, hide the table
        if( supplier && customer == false){
            alert('hide table');
        }
        // if supplier is checked, show supplier, else hide supplier
    });
您还需要将
供应商
错误
进行比较,以便使用:

if( supplier == true && customer == false){
    alert('hide table');
}
或:

而不是:

if( !supplier && !customer){
    alert('hide table');
}
在您的上一行中,
供应商
是布尔变量。所以你可以用你想用的方式

 var supplier = $('.supplier').is(":checked");
请尝试以下操作:

   if( !supplier && !customer){
        alert('hide table');
    }


您可以使用betwise运算符

if (!supplier && !customer){
    alert('hide table');
}

在前面的回答中,有一点没有真正提到(尽管答案很好),那就是您只在单击
.supplier
时调用函数。我可以想象,当您单击
.supplier
.customer
时,您想要调用此函数。如果是这样,您需要将
.customer
添加到选择器中:

if( supplier & customer == false){
    //alert
}

您必须检查这两个条件使用此
supplier==false&&customer==false
而不是
supplier&&customer==false
。非常感谢兄弟,我忘记插入了。客户:D
if (supplier == false && customer == false){
    alert('hide table');
}
if (!supplier && !customer){
    alert('hide table');
}
if( supplier & customer == false){
    //alert
}
$('.supplier, .customer').on('click', function(){
    var supplier = $('.supplier').is(":checked");
    var customer = $('.customer').is(":checked");

    // if both is unchecked, hide the table
    if( !supplier && !customer){
        alert('hide table');
    }
    // if supplier is checked, show supplier, else hide supplier
});