jQuery filter a list using simple select box

2019-08-08 21:04发布

I would like to filter this simple LIST with jquery or javascript. The only exemple i found is with multiple selectedbox like this one: http://jsfiddle.net/EfEYQ/

Can you please help me? Thx in advance

<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>

1条回答
We Are One
2楼-- · 2019-08-08 21:41

Here you go, mate - pretty much the same as your example above:

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();
        }
    });
});​​​​​​​​​​​​​​
查看更多
登录 后发表回答