我正在尝试在动态 html 表上应用多个过滤器。它工作正常,但第一行包含标题,如 empID、Name 等。不能将其视为唯一的。我试过这样的事情,但它不起作用。
$(document).ready(function(){
var $rows = $('#tblData tr');
console.log("akshansh");
$('#empId, #empName,#status').on('input', function() {
var val1 = $.trim($('#empId').val()).replace(/ +/g, ' ').toLowerCase();
var val2 = $.trim($('#empName').val()).replace(/ +/g, ' ').toLowerCase();
var val3= $.trim($('#status').val()).replace(/ +/g, ' ').toLowerCase();
$rows.show().filter(function() {
var text1 = $(this).find('tr:not(:first),td:nth-child(1)').text().replace(/\s+/g, ' ').toLowerCase();
var text2 = $(this).find('tr:not(:first),td:nth-child(2)').text().replace(/\s+/g, ' ').toLowerCase();
var text3 = $(this).find('tr:not(:first),td:nth-child(n+2)').text().replace(/\s+/g, ' ').toLowerCase();
return !~text1.indexOf(val1) || !~text2.indexOf(val2)|| !~text3.indexOf(val3);
}).hide();
});
});
另外第三列是日期字段,所以有没有办法可以按日期过滤数据?
你错过了:在第一个孩子之前
$("#tblData tr:not(:first-child)").hide();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句