如何在jquery内容中连接两个filter? filter1和filter2连接结果

我是jquery的新手。 我在jquery中创建了filter,我想将它们连接在一起以显示仅被点击的内容。 我怎么能这样做? 对不起,我的英语不好。 我尝试了很多个小时,我正在构建这个:

$("button").click(function() { var show = $(this).attr('class'); $('.post').each(function(){ $(this).show(); var test = $(this).attr('class'); if (test.indexOf(show) < 0) $(this).hide(); }); }); 
  

FIRST

TWO


One Washington
One Philadelphia
Two Philadelphia
Two Washington
One Philadelphia
Two Washington
One Philadelphia

有关每个步骤的详细信息,请参阅逻辑中的注释。

 $("button").click(function() { //remove the selected class from the previously selected button $(this).closest('.filter').find('button.selected').removeClass('selected'); //put the class on the button you clicked $(this).addClass('selected'); //get the data-filter off of the selected buttons and join them into a selector var filter = '.'+ $('button.selected').map(function(){ return $(this).data('filter'); }).get().join('.'); //hide all the posts, and then show those that match $('.post').hide().filter(filter).show(); }); 
  

FIRST

TWO


One Washington
One Philadelphia
Two Philadelphia
Two Washington
One Philadelphia
Two Washington
One Philadelphia