多重过滤器Jquery
我正在尝试为某些内容创建筛选器。多重过滤器Jquery,jquery,html,filter,Jquery,Html,Filter,我正在尝试为某些内容创建筛选器。 但是我不确定如何解决这个问题: html 当我尝试单独切换大小或颜色时,效果很好。 但如果我试图把它们混在一起,它就不会像预期的那样起作用 如果我单击“切换红色”和“切换小”,它应该只显示大的蓝色。它的工作方式应该是正常的。 例如,一旦单击红色,第一个和第二个div将被隐藏,第三个和第四个div将显示: <div id="content" class="red small" style="display: none;"></div> &
但是我不确定如何解决这个问题: html 当我尝试单独切换大小或颜色时,效果很好。
但如果我试图把它们混在一起,它就不会像预期的那样起作用 如果我单击“切换红色”和“切换小”,它应该只显示大的蓝色。它的工作方式应该是正常的。
例如,一旦单击红色,第一个和第二个div将被隐藏,第三个和第四个div将显示:
<div id="content" class="red small" style="display: none;"></div>
<div id="content" class="red big" style="display: none;"></div>
<div id="content" class="blue small"></div>
<div id="content" class="blue big"></div>
为了确保你有一个“多重过滤器”,你可能想在你的按钮中添加被切换的信息,然后只切换(或显示/隐藏)与你所有过滤器相关的元素
$(".toggle").click(function() {
$(this).toggleClass('toggled');
toggledIds = []
$('.toggled').each(function(i, e){
toggledIds[toggledIds.length] = $(e).attr('id')
});
// Now you can do whatever you want with the list of the ids
});
如果你点击红色,然后点击大的,然后点击蓝色,你会看到红色,大的,蓝色的,它的工作方式应该是这样的。例如,一旦单击红色,第一个和第二个div将被隐藏,第三个和第四个div将显示:
<div id="content" class="red small" style="display: none;"></div>
<div id="content" class="red big" style="display: none;"></div>
<div id="content" class="blue small"></div>
<div id="content" class="blue big"></div>
为了确保你有一个“多重过滤器”,你可能想在你的按钮中添加被切换的信息,然后只切换(或显示/隐藏)与你所有过滤器相关的元素
$(".toggle").click(function() {
$(this).toggleClass('toggled');
toggledIds = []
$('.toggled').each(function(i, e){
toggledIds[toggledIds.length] = $(e).attr('id')
});
// Now you can do whatever you want with the list of the ids
});
如果你点击红色,然后点击大的,然后点击蓝色,你会得到红色,大的,蓝色的
$(".toggle").click(function() {
$(this).toggleClass('toggled');
toggledIds = []
$('.toggled').each(function(i, e){
toggledIds[toggledIds.length] = $(e).attr('id')
});
// Now you can do whatever you want with the list of the ids
});