【发布时间】:2015-09-05 18:03:53
【问题描述】:
这个问题的标题可能会产生误导,但我想不出更好的措辞。
让我进入正题。我正在使用按钮来过滤状态表。如果我有按钮 A 和按钮 B 处于活动状态,我只想显示 A 和 B,其余的都是隐藏的。目前我只能让它显示 A 或 B,不能同时显示。
var aSelected = [];
$(".admin_view #filterTable tr td button").on("click", function() {
$(this).toggleClass("selected"); //class to show user button is active
//Add to array if not in already
if ($.inArray(this.id,aSelected) == -1) {
aSelected.push(this.id);
//Remove from array if button is not active
} else if ($.inArray(this.id,aSelected) >= 0) {
aSelected.splice(aSelected.indexOf(this.id), 1);
}
//Show all if array is empty
if (!aSelected.length) {
$(".admin_view #applicantTable tbody tr").each(function() {
$(".admin_view #applicantTable tbody tr").removeClass("hidden");
});
}
//This is the section I need help with
$.map(aSelected, function(a) {
$(".admin_view #applicantTable tbody tr").not("."+a).addClass("hidden");
$(".admin_view #applicantTable tbody tr."+a).removeClass("hidden");
});
});
我需要找到一种方法来与整个数组进行比较,而不是与一个部分进行比较。
【问题讨论】:
标签: javascript jquery arrays class