设计师在这里学习编码,在我的 js 中或使用 jquery 并不太远。试图让一个复选框过滤器与这个人几乎相同:http: //jsfiddle.net/BCbeU/但似乎无法让它像我正在构建的网站上的 jsfiddle 一样运行。
这是我的复选框的html:
<div class="tags">
<label><input type="checkbox" rel="all"/> Show All </label>
<label><input type="checkbox" rel="one"/> 1 Bedroom </label>
<label><input type="checkbox" rel="two"/> 2 Bedroom </label>
<label><input type="checkbox" rel="below"/> Below $1500 </label>
<label><input type="checkbox" rel="above"/> Above $1500 </label>
</div>
这是我要过滤的项目的 html:
<div id="shelf1-housing">
<ul class="results">
<li class="all one">
<a href="html/sessionone.html">
<div class="box">
<img src="../images/apartment2.jpg">
<h4>3 Bedroom Apartment</h4>
<h5>$1500 a month</h5>
</div>
</a>
</li>
<li class="all below">
<a href="html/sessionone.html">
<div class="box">
<img src="../images/apartment1.jpg">
<h4>3 Bedroom Apartment</h4>
<h5>$1500 a month</h5>
</div>
</a>
</li>
<li class="below all">
<a href="html/sessionone.html">
<div class="box">
<img src="../images/apartment2.jpg">
<h4>3 Bedroom Apartment</h4>
<h5>$1500 a month</h5>
</div>
</a>
</li>
<li class="all above">
<a href="html/sessionone.html">
<div class="box">
<img src="../images/apartment1.jpg">
<h4>3 Bedroom Apartment</h4>
<h5>$1500 a month</h5>
</div>
</a>
</li>
<li class="all">
<a href="html/sessionone.html">
<div class="box">
<img src="../images/apartment2.jpg">
<h4>3 Bedroom Apartment</h4>
<h5>$1500 a month</h5>
</div>
</a>
</li>
</ul><!--End of Results-->
</div><!--End of Shelf1-Housing-->
这是javascript:
$('div.tags').delegate('input:checkbox', 'change', function(){
var $lis = $('.results > li').hide();
//For each one checked
$('input:checked').each(function(){
$lis.filter('.' + $(this).attr('rel')).show();
});
});
提前感谢您的帮助。仍在学习基础知识,他们还没有让我走这么远,很快,但还没有:)