[英]I have a search and checkbox filter that should be filtering together, but my checkbox filter code isn't working
出於某種原因,我的復選框過濾器不起作用,但搜索過濾器起作用。 它出什么問題了? 這是我的搜索+復選框過濾器:
// search filter (working)
$(document).ready(function() {
$("#myInput").keyup(function() {
// Retrieve the input field text and reset the count to zero
var filter = $(this).val(),
count = 0;
// Loop through the comment list
$("tr").each(function() {
// If the list item does not contain the text phrase fade it out
if ($(this).text().search(new RegExp(filter, "i")) < 0) {
$(this).fadeOut(0).addClass('hidden');
// Show the list item if the phrase matches and increase the count by 1
} else {
$(this).show().removeClass('hidden');
count++;
}
});
// Update the count
var numberItems = count;
$("#filter-count").text("Number of Rows = " + count);
});
});
// checkbox filter (not working)
$(document).ready(function() {
$('#myTable tr' + $(this).attr('rel')).show();
$('div.modal-body').find('input:checkbox').live('click', function() {
if ($('div.modal-body').find('input:checkbox:checked').length > 0) {
$('#myTable tr').hide();
$('div.modal-body').find('input:checked').each(function() {
$('#myTable tr' + $(this).attr('rel')).not('.hidden').show();
});
} else {
$('#myTable tr').not('.hidden').show();
}
});
});
live
在最新版本的jquery中已貶值,請使用on
代替您的事件。
$(document).ready(function () {
$('#myTable tr' + $(this).attr('rel')).show();
$('div.modal-body').find('input:checkbox').on('change', function () {
if($('div.modal-body').find('input:checkbox:checked').length > 0){
$('#myTable tr').hide();
$('div.modal-body').find('input:checked').each(function () {
$('#myTable tr' + $(this).attr('rel')).not('.hidden').show();
});
} else {
$('#myTable tr').not('.hidden').show();
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.