你好,我有一個公寓列表,我需要通過複選框按類型(如工作室,1間臥室,2間臥室)過濾它們。 你可以在http://jsfiddle.net/YByCk/1/ 看到演示如果你選擇例如1臥室和2臥室來顯示1臥室和2臥室的結果(如果已經選中1),我不知道該如何做到這一點。 問題是,當你檢查第二個複選框將只顯示最後一個複選框過濾器,不會保持其他複選框被選中。Jquery過濾列表通過複選框的DIV
//function count results after filter
function divcount()
{
var resCount = $('.listing').filter(":visible").size();
//alert(resCount)
$("#contResults").html(resCount + ' results');
}
//bedrooms filter
$("#Studio").click(function(){
if($("#Studio").is(':checked'))
{
$('.listing[bedrooms!="Studio"]').hide();
divcount();
}
if(!$("#Studio").is(':checked'))
{
$('.listing[bedrooms!="Studio"]').show();
divcount();
}
});
$("#1B").click(function(){
if($("#1B").is(':checked'))
{
$('.listing[bedrooms!="1 Bedroom"]').hide();
divcount();
}
if(!$("#1B").is(':checked'))
{
$('.listing[bedrooms!="1 Bedroom"]').show();
divcount();
}
});
$("#2B").click(function(){
if($("#2B").is(':checked'))
{
$('.listing[bedrooms!="2 Bedroom"]').hide();
divcount();
}
if(!$("#2B").is(':checked'))
{
$('.listing[bedrooms!="2 Bedroom"]').show();
divcount();
}
});
$("#3B").click(function(){
if($("#3B").is(':checked'))
{
$('.listing[bedrooms!="3 Bedroom"]').hide();
divcount();
}
if(!$("#3B").is(':checked'))
{
$('.listing[bedrooms!="3 Bedroom"]').show();
divcount();
}
});
$("#4B").click(function(){
if($("#4B").is(':checked'))
{
$('.listing[bedrooms!="4 Bedroom"]').hide();
divcount();
}
if(!$("#4B").is(':checked'))
{
$('.listing[bedrooms!="4 Bedroom"]').show();
divcount();
}
});
$("#5B").click(function(){
if($("#5B").is(':checked'))
{
$('.listing[bedrooms!="5 Bedroom"]').hide();
divcount();
}
if(!$("#5B").is(':checked'))
{
$('.listing[bedrooms!="5 Bedroom"]').show();
divcount();
}
});
有什麼想法嗎?
謝謝
它正在做你告訴它做的事情。您應該創建一個應用過濾器函數,只要點擊任何複選框就會被調用。然後檢查每個複選框的狀態並隱藏/顯示適當的值。 – 2012-02-07 16:52:29
謝謝科裏我會盡力...任何快速提示? – Teodor 2012-02-07 17:09:25