j查询 if 语句中的多个条件

jQuery multiple conditions within if statement

本文关键字:条件 查询 if 语句      更新时间:2023-09-26

这个循环跳过某些键的语法是什么? 我编写它的方式无法正常工作。

 $.each(element, function(i, element_detail){
    if (!(i == 'InvKey' && i == 'PostDate')) {
        var detail = element_detail + ' ';
        $('#showdata').append('<div class="field">' + i + detail + '</div>');
       }
 });

试试

if (!(i == 'InvKey' || i == 'PostDate')) {

if (i != 'InvKey' || i != 'PostDate') {

也就是说,如果我不等于InvKeyPostDate

i == 'InvKey' && i == 'PostDate'永远不会成立,因为i永远不可能同时等于两个不同的东西。

你可能正在尝试写作

if (i !== 'InvKey' && i !== 'PostDate')) 

更通用的方法:

if ( ($("body").hasClass("homepage") || $("body").hasClass("contact")) && (theLanguage == 'en-gb') )   {
       // Do something
}