【发布时间】:2014-11-21 12:50:16
【问题描述】:
Onload 复选框未选中,并显示所有列表项。 当在这些列表项上选中过滤器时,将显示相关的列表项。 我遇到的问题是,当您再次取消选中所有复选框时,我需要显示所有项目而不是隐藏。
这是我的小提琴...
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
});
});
最终这将用于投资组合,但我会将过滤器/标签分成它们的类别。如果有人想提供建议,将不胜感激。
【问题讨论】: