取消选中所有复选框后,客户端过滤器将显示所有项目 [英] Client side filter show all items when all checkboxes have been deselected

查看:113
本文介绍了取消选中所有复选框后,客户端过滤器将显示所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

未选中复选框,并显示所有列表项. 当在那些过滤器上选中过滤器时,将显示相关的那些列表项. 我遇到的问题是,当您再次取消选中所有复选框时,我需要显示而不是隐藏所有项目.

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.

推荐答案

这是小提琴 http://jsfiddle. net/B9Hnu/125/

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

// your logic
}

这篇关于取消选中所有复选框后,客户端过滤器将显示所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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