为.each()添加两个包含



我有一个有两个过滤器的表一个搜索框和一个选择框。最后,我希望搜索框过滤器只搜索由selectbox过滤的表项。

例如:在选择框中选择了Pending Qualification,因此只显示Pending Qualification的行(其余的隐藏)。当我搜索时,我只想搜索可见的行。

理想情况下,我想在.each(function(e))

之前添加另一个条件

我试过这个,但它似乎不工作。

CSS

.hidden {
    display:none;
}

这里是containsi

$.extend($.expr[':'], {
    'containsi': function (elem, i, match, array) {
        return (elem.textContent || elem.innerText || '').toLowerCase()
        .indexOf((match[3] || "").toLowerCase()) >= 0;
    }
});//end of case insensitive chunk

所有这些仍然过滤所有数据

$("#filterItems .hideThis").not(":containsi('" + searchSplit + "'):contains('"+ selectValue + "')").each(function (e) {
    //add a "hidden" class that will remove the item from the list
    $(this).addClass('hidden');
});
下<<p> /strong>
$("#filterItems .hideThis").not(":containsi('" + searchSplit + "')").each(function (e) {
    if($("#filterItems .hideThis:contains('" + selectValue + "')")){
       //add a "hidden" class that will remove the item from the list
       $(this).addClass('hidden');
    }
});

我也累了检查。hidden

$("#filterItems .hideThis").not(":containsi('" + searchSplit + "')").each(function (e) {
    if(!($(this).hasClass('hidden'))){
        //add a "hidden" class that will remove the item from the list
        $(this).addClass('hidden');
    }
});

当前JSFiddle如果你想看到它

你把事情弄复杂了,我建议:

$('#select-Qualification').on('change', filter).change();
$("#search-text").on('keyup', filter).keyup();
function filter() 
{
    var selectValue = $('#select-Qualification').val();
    var query = $.trim($("#search-text").val()).toLowerCase();
    // filter based on the select's value
    var $col = $("#filterItems .hideThis").addClass('hidden').filter(function () {
        return $('td:eq(3)', this).text() === selectValue;
    });
    // filter based on the search input's value
    if (query.length) {
        $col = $col.filter(function() {
           return $(this).text().toLowerCase().indexOf(query) > -1;
        });
    }
    $col.removeClass('hidden');
}
http://jsfiddle.net/5LaxC/

最新更新