2012-07-03 113 views
0

我想获得一个页面来过滤页面上的不同参数适合住宿部分。我无法让过滤器一起工作,所以如果用户点击一个部分,它将与另一个部分一起工作。jquery多复选框过滤器

的小提琴是http://jsfiddle.net/ktcle/YEtgM/2/

感谢您的帮助

$('input').change(function(){ 
$('input').each(function(){ 
    var checked = $(this).attr('checked') || false; 
    var numberofrooms = $(this).data('bedrooms'); 
    var sitelocation = $(this).data('location'); 
    $('li').each(function(){ 
     if ($(this).data('bedrooms')==numberofrooms){ 
      checked ? $(this).show() : $(this).hide(); 
     } 

     if ($(this).data('location')==sitelocation){ 
      checked ? $(this).show() : $(this).hide(); 
     } 

    }); 
}); 

});

+0

有什么理由你的投入没有名称和值的属性? – j08691

+0

没有理由,这只是在测试,直到它的工作,然后我将它们添加在 –

回答

0

这样的事情怎么样jsFiddle example

我给你的输入值,有几个原因,但这里的jQuery的:

$('input').change(function() { 
    var room_array = new Array(), 
     loc_array = new Array(); 
    $('.br').each(function() { 
     if ($(this).is(':checked')) { 
      room_array.push($(this).data('bedrooms')); 
     } 
    }); 
    $('.loc').each(function() { 
     if ($(this).is(':checked')) { 
      loc_array.push($(this).data('location')); 
     } 
    }); 
    $('li').each(function() { 
     if ($.inArray($(this).data('location'), loc_array) > -1 && $.inArray($(this).data('bedrooms'), room_array) > -1) { 
      $(this).show(); 
     } else { 
      $(this).hide(); 
     } 
    }); 
});​ 
+0

谢谢,因为它是真的有帮助,但我可能不太清楚,我需要的是不同的数据集独立工作。所以如果用户点击伦敦,他们会看到所有的伦敦,然后当用户点击2个房间时,它会在不同的数据集上再次过滤,因此只显示伦敦的2个房间。我将使用一些不同的数据集 谢谢 –