javascript - 如何检查条件中的两个变量?

标签 javascript jquery

$('.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
    });

如果我不检查.supplier 和.customer,我想隐藏表格

非常感谢你。

最佳答案

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

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

您还需要将 supplierfalse 进行比较,以便您可以使用:

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

或者:

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

而不是:

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

关于javascript - 如何检查条件中的两个变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22630128/

相关文章:

javascript - 无法从我的数组中删除偶数

javascript - 如何在node.js中记录请求对象的所有属性?

javascript - 连接 SVG 矩形

javascript - jQuery .submit 方法

javascript - 如何在跨度中添加底部填充

jquery - 从数据表中获取隐藏行内容并将其与表单一起提交

javascript - Javascript 和 jQuery 中图像上的可点击网格

javascript - 在 nuxt.js 身份验证中,用户始终重定向到刷新时登录

javascript - Angular : how to get input value without ng-model

javascript - 为什么第二个函数声明赢了,即使我在它之前返回?