我如何在多个表中搜索?我有这个代码,但这只适用于我的一个表格。我总共有4张桌子。如何在多个表中搜索?
这是我在我的表中的“东西”后搜索的代码。
$(document).ready(function() {
$('#search').keyup(function() {
searchTable($(this).val());
});
});
function searchTable(inputVal) {
var table = $('#searchTable');
table.find('tr').each(function(index, row) {
var allCells = $(row).find('td');
if(allCells.length > 0) {
var found = false;
allCells.each(function(index, td) {
var regExp = new RegExp(inputVal, 'i');
if(regExp.test($(td).text())) {
found = true;
return false;
}
});
if(found == true) $(row).show();
else $(row).hide();
}
});
}
我已经剥夺我的码表,使其看起来更容易管理了
问题就出在“搜索田部”只运行表1通过,而不是剩余
表1:
<table class="table" id="searchTable">
表2:
<table class="table" id="searchTable">
表3:
<table class="table" id="searchTable">
表4:
<table class="table" id="searchTable">
该id应该是唯一的..看看这个例子http://jsfiddle.net/6hRNf/ – BeNdErR 2013-02-13 11:25:20