Client side filter show all items when all checkboxes have been deselected

无人久伴 提交于 2019-12-24 02:56:10

问题


Onload the check boxes are unchecked and the all list items are displayed. When a filter is checked on the those list items relating are be displayed. The problem i am having is when you uncheck all of the checkboxes again i need all items to show rather than hide.

Here's my fiddle...

http://jsfiddle.net/amesy/B9Hnu/124/

$(function() {

var $checkboxes = $("input[id^='type-']");
$('input[type=checkbox]:checked').attr('checked', false);

$checkboxes.change(function() {
    var selector = '';
    $checkboxes.filter(':checked').each(function() { // checked 
        selector += '.' + this.id.replace('type-', '') + ', ';
        // builds a selector like '.A, .B, .C, ' 
    });
    selector = selector.substring(0, selector.length - 2); // remove trailing ', '
    $('#list li').hide() // hide all rows
    .filter(selector).show(); // reduce set to matched and show
});

});

Ultimately this will be used in a portfolio but I will be splitting the filters/tags up into their categories. If anyone wants to advise it would be most appreciated.


回答1:


here is fiddle http://jsfiddle.net/B9Hnu/125/

if( $('input[type=checkbox]:checked').length<=0)
{
//show all
}
else{

// your logic
}


来源:https://stackoverflow.com/questions/27061828/client-side-filter-show-all-items-when-all-checkboxes-have-been-deselected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!