我正在使用以下函数根据工作正常的输入字段过滤表格。
目前这是指我说“ 'td:eq(3)'
”的固定列索引。
如何在此处引用我的变量“colIndex”而不是使用固定列索引?另外,有没有办法可以根据我的第一个代码行获取当前表的 id,这样我就不必引用下面的表类(“myTable”)?
我的代码(工作):
$('.myClass').on('keyup', function () {
var colIndex = $(this).closest('th').index();
var regex = new RegExp($(this).val().toLowerCase(), "i");
$('.myTable').find('tr:gt(1)').each(function () {
if ($(this).find('td:eq(3)').text().match(regex) == null) {
$(this).hide();
} else {
$(this).show();
}
});
});
非常感谢您对此提供的任何帮助,蒂姆。