JQuery选择行中td内包含特定文本的所有行

时间:2022-11-30 22:18:10

I have a table for which I am attempting to select all rows which have a td containing the text 'Test' and then hide the td with class 'ms-vb-icon' on all the matched rows

我有一个表,我试图选择所有包含文本'Test'的td的行,然后在所有匹配的行上隐藏带有'ms-vb-icon'类的td

I intitally had the code below but this only hide the class on the last matched row

我真的有下面的代码,但这只隐藏了最后一个匹配行上的类

 $("td:contains('test'):last").parent().children(".ms-vb-icon").css("visibility","hidden");

So I tried this but its not working...

所以我尝试了这个,但它不起作用......

 $("tr:has(td:contains('test')").each(function(){
  (this).children(".ms-vb-icon").css("visibility","hidden");
  });

Simplified html look like this:

简化的HTML看起来像这样:

<table>
<tbody>
<tr>
<td class=ms-vb-icon></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>test</td>
</tr>
</tbody>
<table>

3 个解决方案

#1


31  

Try:

尝试:

$("tr td:contains('test')").each(function(){
  $(this).siblings('td.ms-vb-icon').css("visibility","hidden");
});

Demo here.

在这里演示。

#2


8  

I guess you are missing ')' .It worked for me:

我想你错过了')'。它对我有用:

$("tr:has(td:contains('1'))").each(function () {

#3


6  

Try with

试试吧

$("tr:has(td:contains('test')").each(function(){
    $(this).parent().children(".ms-vb-icon").css("visibility","hidden");
});

The class .ms-vb-icon is a child of the tr while the $(this) function refer to the td

类.ms-vb-icon是tr的子类,而$(this)函数引用td

#1


31  

Try:

尝试:

$("tr td:contains('test')").each(function(){
  $(this).siblings('td.ms-vb-icon').css("visibility","hidden");
});

Demo here.

在这里演示。

#2


8  

I guess you are missing ')' .It worked for me:

我想你错过了')'。它对我有用:

$("tr:has(td:contains('1'))").each(function () {

#3


6  

Try with

试试吧

$("tr:has(td:contains('test')").each(function(){
    $(this).parent().children(".ms-vb-icon").css("visibility","hidden");
});

The class .ms-vb-icon is a child of the tr while the $(this) function refer to the td

类.ms-vb-icon是tr的子类,而$(this)函数引用td