jquery 多个下拉过滤器菜单 [英] jquery multiple dropdown filter menu

查看:15
本文介绍了jquery 多个下拉过滤器菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我根据多个下拉菜单选择隐藏和显示图片.我正在尝试让 2 个和可能更多的下拉菜单协同工作以优化搜索.

I have pictures hiding and showing based on a multiple dropdown menu selection. I am trying to have the 2 and possible more dropdown menus working together to refine a search.

如果我在第一个下拉列表中选择一个项目,我想应用第二个过滤器,依此类推以及任何其他下拉列表.

If I select an item in the first dropdown, I would like to apply the second filter and so on with any additional dropdown.

我需要一些有关 jquery 的帮助.我目前的问题是第二个过滤器永远不会启动.它会被覆盖并重置过滤器.如果可能,我想添加第三个过滤器以进一步缩小搜索范围,以准确找到我正在寻找的内容.这是一些示例代码..

I need some help with the jquery. My current problem is the 2nd filter never kicks in. It gets overwritten and resets the filter. If possible, I would like to add a 3rd filter to narrow the search even more to find exactly what I am looking for. Here is some sample code..

$('select').change(function(){
var current = $(this).attr('value');

if(current == 'all'){
    $('#FilterContainer').children('div.all').show();
} 

else {

    $('#FilterContainer').children('div:not(.' + current + ')').hide();
$('#FilterContainer').children('div.' + current).show();
 }

  return false;
})

HTML

  <p>Filter: </p>
        <select class="filterby">
        <option value="all"><h5>Show All</h5></option>
        <option value="1"><h5>One</h5></option>
        <option value="2"><h5>Two</h5></option>
        <option value="3"><h5>Three</h5></option>
      </select>



      <p>Location: </p>
        <select class="filterby">
        <option value="all"><h5>All Locations</h5></option>
        <option value="nj"><h5>NJ</h5></option>
        <option value="ny"><h5>NY</h5></option>
        <option value="pa"><h5>PA</h5></option>
      </select>


  <div id="FilterContainer">

  <div class="all 1 nj">Test One NJ</div>
  <div class="all 1 ny">Test One NY</div>
  <div class="all 1 pa">Test One PA</div>
  <div class="all 2 nj">Test Two NJ</div>
  <div class="all 2 ny">Test Two NY</div>
  <div class="all 2 pa">Test Two PA</div>
  <div class="all 3 nj">Test Three NJ</div>
  <div class="all 3 ny">Test Three NY</div>
  <div class="all 3 pa">Test Three PA</div>
  <div class="all 1 nj">Test One NJ</div>
  <div class="all 1 pa">Test One PA</div>
  <div class="all 1 pa">Test One PA</div>
  <div class="all 2 nj">Test Two NJ</div>
  <div class="all 2 ny">Test Two NY</div>
  <div class="all 2 ny">Test Two NY</div>

推荐答案

试试这个 -

$("select.filterby").change(function(){
    var filters = $.map($("select.filterby").toArray(), function(e){
        return $(e).val();
    }).join(".");
    $("div#FilterContainer").find("div").hide();
    $("div#FilterContainer").find("div." + filters).show();
});

使用现场演示

这篇关于jquery 多个下拉过滤器菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆