jQuery:迭代子级和布尔值

jQuery:迭代子级和布尔值,jquery,boolean,each,Jquery,Boolean,Each,如果父td中的每个.itemToFilter子项都未通过测试(因此返回所有TRUE),则应执行警报(“hello world”)。但事实并非如此 第一个IF语句工作正常,我已经用警报对它进行了测试。但不是第二个 var businessTypePullDownValue = $('.businessTypePullDown').val(); $('.businessTypeRow td').each( function() { var foundOne = $(this).child

如果父td中的每个.itemToFilter子项都未通过测试(因此返回所有TRUE),则应执行警报(“hello world”)。但事实并非如此

第一个IF语句工作正常,我已经用警报对它进行了测试。但不是第二个

var businessTypePullDownValue = $('.businessTypePullDown').val();

$('.businessTypeRow td').each( function() {

    var foundOne = $(this).children('.itemToFilter').each( function() {                

        if(($(this).attr('value') == businessTypePullDownValue)) {
            return true; 
        }
    });

    if(!foundOne) {
        alert('hello world');
    }

});​

中返回
true
,然后继续下一次迭代。您需要执行以下操作:

var foundOne = false;

$(this).children('.itemToFilter').each( function() {                

    if(($(this).attr('value') == businessTypePullDownValue)) {
        foundOne = true;
        return false;  // break the loop
    }
});

if(!foundOne) {
    alert('hello world');
}

中返回
true
,然后继续下一次迭代。您需要执行以下操作:

var foundOne = false;

$(this).children('.itemToFilter').each( function() {                

    if(($(this).attr('value') == businessTypePullDownValue)) {
        foundOne = true;
        return false;  // break the loop
    }
});

if(!foundOne) {
    alert('hello world');
}

请提供源html请提供源html