如何在jquery内容中连接两个过滤器?过滤器 1 和过滤器 2 连接结果

双腰带

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

$("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();
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h2>FIRST</h2>
<div id='filter'>
    <button class='all'>All</button>
    <button class='1'>One</button>
    <button class='2'>Two</button>
</div>
<h2>TWO</h2>
<div id='filter'>
    <button class='all'>All</button>
    <button class='aa'>Washington</button>
    <button class='bb'>Philadelphia</button>
</div>

<br>
<div id='posts'>
    <div class='all post 1 aa'>One Washington</div>
    <div class='all post 1 bb'>One Philadelphia</div>
    <div class='all post 2 bb'>Two Philadelphia</div>
    <div class='all post 2 aa'>Two Washington</div>
    <div class='all post 1 bb'>One Philadelphia</div>
    <div class='all post 2 aa'>Two Washington</div>
    <div class='all post 1 bb'>One Philadelphia</div>
</div>

塔普拉

有关每个步骤正在执行的操作的详细信息,请参阅逻辑中的注释。

$("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();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h2>FIRST</h2>
<!-- we use a class because an id cannot be repeated
     and we want to select both our filters later -->
<div class='filter'>
    <!-- data fields let us separate the classes from the data that
         is used for the filter -->
    <button data-filter='all'>All</button>
    <button data-filter='1'>One</button>
    <button data-filter='2'>Two</button>
</div>
<h2>TWO</h2>
<div class='filter'>
    <button data-filter='all'>All</button>
    <button data-filter='aa'>Washington</button>
    <button data-filter='bb'>Philadelphia</button>
</div>

<br>
<div id='posts'>
    <div class='all post 1 aa'>One Washington</div>
    <div class='all post 1 bb'>One Philadelphia</div>
    <div class='all post 2 bb'>Two Philadelphia</div>
    <div class='all post 2 aa'>Two Washington</div>
    <div class='all post 1 bb'>One Philadelphia</div>
    <div class='all post 2 aa'>Two Washington</div>
    <div class='all post 1 bb'>One Philadelphia</div>
</div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

过滤器NSFetchedResultsController结果swift 2

来自分类Dev

过滤器NSFetchedResultsController结果swift 2

来自分类Dev

与过滤器交叉连接?

来自分类Dev

如何在Solr中标记由“ AND”运算符连接的两个过滤器?

来自分类Dev

在 JTable 过滤器中应用和调用 2 个过滤器

来自分类Dev

外连接中过滤器的行为

来自分类Dev

如何在 angular2 中创建独特的过滤器过滤器组件

来自分类Dev

如何连接两个可用作Lazarus过滤器的DBLookUpCombobox

来自分类Dev

限制过滤器结果?

来自分类Dev

过滤器数量> 1

来自分类Dev

如何在 Angular 2 中使用 Angular 1.x 的过滤器?

来自分类Dev

连接和过滤器的MySQL查询问题

来自分类Dev

非连接形态过滤器

来自分类Dev

左连接带过滤器

来自分类Dev

查看网格-连接过滤器

来自分类Dev

带过滤器的dplyr自连接

来自分类Dev

带过滤器的MySQL连接表

来自分类Dev

Laravel 雄辩的多表连接与过滤器

来自分类Dev

在Angular2中,如何检测到过滤器/管道未返回任何结果

来自分类Dev

有没有一种方法可以从连接过滤器和其他过滤器中导出等效过滤器?

来自分类Dev

使用包含过滤器在环回中连接两个模型

来自分类Dev

如何比较两个ArrayList和GET列表1使用过滤器Java流

来自分类Dev

jQuery / Javascript-连接两个过滤器-仅显示tr与td匹配数组

来自分类Dev

在Couchbase中应如何使用“键”和“键”过滤器来过滤视图结果?

来自分类Dev

将2个过滤器应用于集合,但仅使用1个(AngularJS)

来自分类Dev

将2个过滤器应用于集合,但仅使用1个(AngularJS)

来自分类Dev

如何向连接表添加过滤器

来自分类Dev

使用 MongDB C# 驱动程序连接两个集合的查询中的 NOT IN 过滤器

来自分类Dev

如何在 Ionic 2 中为 IOS 使用货币和日期过滤器?

Related 相关文章

  1. 1

    过滤器NSFetchedResultsController结果swift 2

  2. 2

    过滤器NSFetchedResultsController结果swift 2

  3. 3

    与过滤器交叉连接?

  4. 4

    如何在Solr中标记由“ AND”运算符连接的两个过滤器?

  5. 5

    在 JTable 过滤器中应用和调用 2 个过滤器

  6. 6

    外连接中过滤器的行为

  7. 7

    如何在 angular2 中创建独特的过滤器过滤器组件

  8. 8

    如何连接两个可用作Lazarus过滤器的DBLookUpCombobox

  9. 9

    限制过滤器结果?

  10. 10

    过滤器数量> 1

  11. 11

    如何在 Angular 2 中使用 Angular 1.x 的过滤器?

  12. 12

    连接和过滤器的MySQL查询问题

  13. 13

    非连接形态过滤器

  14. 14

    左连接带过滤器

  15. 15

    查看网格-连接过滤器

  16. 16

    带过滤器的dplyr自连接

  17. 17

    带过滤器的MySQL连接表

  18. 18

    Laravel 雄辩的多表连接与过滤器

  19. 19

    在Angular2中,如何检测到过滤器/管道未返回任何结果

  20. 20

    有没有一种方法可以从连接过滤器和其他过滤器中导出等效过滤器?

  21. 21

    使用包含过滤器在环回中连接两个模型

  22. 22

    如何比较两个ArrayList和GET列表1使用过滤器Java流

  23. 23

    jQuery / Javascript-连接两个过滤器-仅显示tr与td匹配数组

  24. 24

    在Couchbase中应如何使用“键”和“键”过滤器来过滤视图结果?

  25. 25

    将2个过滤器应用于集合,但仅使用1个(AngularJS)

  26. 26

    将2个过滤器应用于集合,但仅使用1个(AngularJS)

  27. 27

    如何向连接表添加过滤器

  28. 28

    使用 MongDB C# 驱动程序连接两个集合的查询中的 NOT IN 过滤器

  29. 29

    如何在 Ionic 2 中为 IOS 使用货币和日期过滤器?

热门标签

归档