jQuery在行中的td中选择包含某些文本的所有行 [英] JQuery select all rows containing certain text within a td in the row
本文介绍了jQuery在行中的td中选择包含某些文本的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表,我试图为此选择所有td包含文本"Test"的行,然后在所有匹配的行上用类"ms-vb-icon"隐藏td
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
我本来就有下面的代码,但这只会在最后匹配的行上隐藏该类
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");
});
简化的html看起来像这样:
Simplified html look like this:
<table>
<tbody>
<tr>
<td class=ms-vb-icon></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>test</td>
</tr>
</tbody>
<table>
推荐答案
尝试:
$("tr td:contains('test')").each(function(){
$(this).siblings('td.ms-vb-icon').css("visibility","hidden");
});
演示此处.
这篇关于jQuery在行中的td中选择包含某些文本的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文