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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4341620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:05:46  来源:igfitidea点击:

JQuery select all rows containing certain text within a td in the row

jqueryjquery-selectors

提问by van

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>

回答by sje397

Try:

尝试:

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

Demo here.

演示在这里

回答by tamarteleco

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

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

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

回答by Lorenzo

Try with

试试

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

The class .ms-vb-iconis a child of the trwhile the $(this)function refer to the td

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