设计师在这里学习编码,而在我的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();
});
});
在此先感谢您的帮助。仍在学习基础知识,他们还没到这为止,很快,但是还没有:)
最佳答案
我是通过从您的网站复制代码来创建小提琴的。请检查http://jsfiddle.net/LXymq/
进行了以下更改:
1)将Li添加回具有Result类的div中。这就是你的经历。
<div class="results"> ... All LIs ... </div>
2)将所有代码添加到$(document).ready函数中,因为在dom准备好之前执行了代码。$(document).ready(function() { ... all your code inside this .... });
4)对图像路径进行硬编码以获得美感。