2012-07-03 112 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個房間。我將使用一些不同的數據集 謝謝 –