Jquery 根据表的特定列验证选定值
请找到小提琴 问题是什么 当用户从drowdown中选择城市时,代码将根据所有td(所有coulmn)验证所选城市名称。但我只想根据“city”列验证所选城市名称Jquery 根据表的特定列验证选定值,jquery,Jquery,请找到小提琴 问题是什么 当用户从drowdown中选择城市时,代码将根据所有td(所有coulmn)验证所选城市名称。但我只想根据“city”列验证所选城市名称 $("#search").change(function () { var value = this.value.toLowerCase().trim(); $("table tr").each(function (index) { if (!index) return; $(this).find("t
$("#search").change(function () {
var value = this.value.toLowerCase().trim();
$("table tr").each(function (index) {
if (!index) return;
$(this).find("td").each(function () {
var id = $(this).text().toLowerCase().trim();
var not_found = (id.indexOf(value) == -1);
$(this).closest('tr').toggle(!not_found);
return not_found;
});
});
});
您可以使用选择器获取第四列,如
选择匹配集中索引n处的元素
代码示例,使用
而不是
$(this).find("td")
注意:它是要匹配的元素的从零开始的索引。您可以使用
:eq(3)
获取第四列,如$(此)。查找(“td:eq(3)”)
谢谢Satpal。你能把你的评论作为答案贴出来吗?这样我就可以接受了。
$(this).find("td")