简体   繁体   English

查找具有特定单元格值的行

[英]find row with a specific cell value

I have a function which finds a row within an html table whos first column contains a specific value... 我有一个函数可以在html表中找到一行,其中第一列包含特定值...

$('#table tr').find('td:eq(0):contains(' + value + ')').parent();

The problem I have is that it returns all rows that have the number 1 in column 0 rather than just the row with 1. (ie, 1, 15, 21 etc..) 我遇到的问题是,它返回列0中具有数字1的所有行,而不仅仅是具有1的行(即1、15、21等)。

Is there an equivalent 'equals' to the 'contains' part of this search or some other way of doing this? 是否有与此搜索的“包含”部分等效的“等于”或执行此操作的其他方式? I can't seem to find one. 我似乎找不到一个。

The simplest would be to use filter : 最简单的方法是使用filter

$('#table tr').filter(function(){
   return $.trim($('td', this).eq(0).text())=="1";
});

Demonstration 示范

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM