简体   繁体   English

如何在表jquery中选择行?

[英]How to select row in table jquery?

I have a table with following columns 我有一个包含以下列的表

|type |status |owner |host | 

I need to select the rows which contain for example (type1 or ... or type20) && (status1 or ... status5) && (owner1 or .. or owner4) etc. 我需要选择包含例如(type1或...或type20)&&(status1或... status5)&&(owner1或..或owner4)等的行。

I know that if I need to have the rows which contains type1&&owner2&&staus1 I can do the following 我知道如果我需要包含type1 && owner2 && staus1的行,我可以执行以下操作

$(table tr:contains('type1'):contains('owner2'):contains('status1'));

Can someone explain how to handle this? 有人可以解释如何处理这个?

I would use something like this: 我会用这样的东西:

var $rows =  $('table tr').filter(function() {
    return ...;
});

where ... is the predicate for matching the cells you want. 其中...是匹配所需单元格的谓词。

Don't forget that you can use this.cells[n] to directly and efficiently access the individual cells, and .textContent (or .innerText ) to read the cells' values. 不要忘记您可以使用this.cells[n]直接有效地访问单个单元格,使用.textContent (或.innerText )来读取单元格的值。

So, part of your predicate could be: 因此,您的谓词的一部分可能是:

this.cells[0].textContent.match(/^type([1-9]|1[0-9]|20)$/)

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

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