【发布时间】:2012-07-11 08:48:40
【问题描述】:
我在link 中找到了此代码:
$(document).ready(function(){
//when a link in the filters div is clicked...
$('#filters a').click(function(e){
//prevent the default behaviour of the link
e.preventDefault();
//get the id of the clicked link(which is equal to classes of our content
var filter = $(this).attr('id');
//show all the list items(this is needed to get the hidden ones shown)
$('#content ul li').show();
/*using the :not attribute and the filter class in it we are selecting
only the list items that don't have that class and hide them '*/
$('#content ul li:not(.' + filter + ')').hide();
});
});
效果很好,但我在选择按钮中使用了此代码。当我选择该选项时,它过滤正常。 但我有不止一个选择 - 实际上是 5 个 - 但我不知道在这种情况下如何处理。
示例:
项目:草莓、苹果、樱桃、橙子、香蕉、葡萄
选择 1 - 所有水果、红色、绿色等
选择 2 - 所有形式、圆角形式、三角形形式。
选择 3 - 完全是另一回事,另一回事
用户可以先选择红色 - First Filter。
那么他可以选择圆形,所以苹果和樱桃就是答案。
我已经尝试只过滤可见图像,但是当我尝试返回信息时出现了一些错误。
在与结果苹果和樱桃相同的示例中,如果用户选择所有水果,则结果必须是苹果、樱桃、橙子和葡萄。
一些建议?
Here is an example code 请注意,过滤器以独立的方式工作。
【问题讨论】:
-
你能发布你正在使用的 HTML 吗?
-
您发布的代码只是按 ID 过滤元素 - 您要求的是完全不同的分类算法。
-
分类算法?听起来很复杂。您是否有任何示例说明我如何在我的情况下使用它?
标签: javascript jquery