我正在使用显示/隐藏来显示基于它们的类属性的项目组。如何进一步过滤这些项目组,以便在 B 列中单击的第二个结果集是第一个结果集的子集。根据我的阅读,我认为过滤器或兄弟可能是关键,但到目前为止我的实验失败了。
在这里,我将更新所需功能的更多解释:单击第一个列表中的项目以显示该列表的子集。单击第二个列表中的项目以细化前一个子集。例如,在第 1 列中,单击红色以仅查看红色项目。然后在第 2 列中,单击大以仅查看大的红色项目。仍在第 2 列时,单击小以仅查看小的红色项目。应该可以通过这种方式进行过滤,直到单击返回到应该显示该列表的新子集的第一列。
http://jsfiddle.net/TorontoDave/Ph98L/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<style>
* {font-family:arial}
.item div {height:50px; width:50px; color:white; font-weight:bold; float:left; margin:1px; text-align:center}
.nav {float:left}
li {float:left; list-style:none; padding-right:30px}
.item .small {font-size:1em}
.item .medium {font-size:2em}
.item .large {font-size:3em}
.item .red {background:red}
.item .green {background:green}
.item .blue {background:blue}
.item .orange {background:orange}
.item .purple {background:purple}
</style>
<script src="../js/jquery-1.5.2.min.js"></script>
</head>
<body>
<h1>Problem: adjust my jQuery code to get column B to filter on column A?</h1>
<div class="nav">
<p>Column A<br>Filter by:</p>
<ul>
<li id="A">A</li>
<li id="red">red</li>
<li id="green">green</li>
<li id="large">large</li>
<li id="small">small</li>
<li id="B">B</li>
<li id="orange">orange</li>
</ul>
</div>
<div class="nav">
<p>Column B<br>Then by:</p>
<ul>
<li id="A">A</li>
<li id="red">red</li>
<li id="green">green</li>
<li id="large">large</li>
<li id="small">small</li>
<li id="B">B</li>
<li id="orange">orange</li>
</ul>
</div>
<div class="item">
<div class="small red A">A</div>
<div class="small green A">A</div>
<div class="small orange A">A</div>
<div class="small purple A">A</div>
<div class="small blue A">A</div>
<div class="medium red A">A</div>
<div class="medium green A">A</div>
<div class="medium orange A">A</div>
<div class="medium purple A">A</div>
<div class="medium blue A">A</div>
<div class="large red A">A</div>
<div class="large green A">A</div>
<div class="large orange A">A</div>
<div class="large purple A">A</div>
<div class="large blue A">A</div>
<div class="small red B">B</div>
<div class="small green B">B</div>
<div class="small orange B">B</div>
<div class="small purple B">B</div>
<div class="small blue B">B</div>
<div class="medium red B">B</div>
<div class="medium green B">B</div>
<div class="medium orange B">B</div>
<div class="medium purple B">B</div>
<div class="medium blue B">B</div>
<div class="large red B">B</div>
<div class="large green B">B</div>
<div class="large orange B">B</div>
<div class="large purple B">B</div>
<div class="large blue B">B</div>
<div class="small red C">C</div>
<div class="small green C">C</div>
<div class="small orange C">C</div>
<div class="small purple C">C</div>
<div class="small blue C">C</div>
<div class="medium red C">C</div>
<div class="medium green C">C</div>
<div class="medium orange C">C</div>
<div class="medium purple C">C</div>
<div class="medium blue C">C</div>
<div class="large red C">C</div>
<div class="large green C">C</div>
<div class="large orange C">C</div>
<div class="large purple C">C</div>
<div class="large blue C">C</div>
</div><!-- //end items -->
<script><!-- to show and hide overlays -->
$(document).ready(function(){
$('li').click(function(){
$('.item div').hide();
$('.'+this.id).show('slow');
});
});
</script>
</body>
</html>