jQuery的使用简单的选择框筛选列表(jQuery filter a list using sim

2019-10-17 10:14发布

我想过滤与jQuery或JavaScript这种简单的列表。 我发现的唯一为例是与多个selectedbox像这样的: http://jsfiddle.net/EfEYQ/

你能帮我么? Thx提前

<select id="filtercountry">
                    <option value='ALL' selected="selected">Select by Country</option>
                    <option value="1">Australia</option>
                    <option value="2">Austria</option>
                    <option value="3">Brazil</option>
                    <option value="4">Canada</option>
</select>


<ul class="submenu">
    <li class="submenucategory">KIDS</li>
    <li id="Cell1" class="lilist">AAAAAA <span class="country">1</span></li>
    <li id="Cell2" class="lilist">BBBBBB <span class="country">2</span></li>
    <li id="Cell3" class="lilist">CCCCCC <span class="country">2</span></li>
    <li id="Cell4" class="lilist">DDDDDD <span class="country">1</span></li>
    <li id="Cell5" class="lilist">EEEEEE <span class="country">3</span></li>
    <li id="Cell6" class="lilist">FFFFFF <span class="country">4</span></li>
</ul>

Answer 1:

在这里,你走了,队友 - 几乎一样的你上面的例子:

DEMO

$('#filtercountry').change(function(){
    var criteria = $(this).val();
    if(criteria == 'ALL'){
        $('.lilist').show();
        return;
    }
    $('.country').each(function(i,option){
        if($(this).html() == criteria){
            $(this).parent().show();
        }else {
            $(this).parent().hide();
        }
    });
});​​​​​​​​​​​​​​


文章来源: jQuery filter a list using simple select box