我有一些我想操纵的HTML。其结构如下:
<tr> <td> <nobr>TEXT_TO_LOOK_FOR</nobr> </td> </tr>
我在这里编写了一个隐藏包含此文本的行的函数,但我只是想知道是否有人可以清理它。我觉得这可能让jquery做的工作超出了它的需要。
我知道我可以搜索包含文本的行,但我希望该函数是健壮的,以便在其他地方找到文本时它不会隐藏行。
function hideRowContainingText(strText)
{
var rowMatches = $('tbody tr td nobr:contains(' + '"' + strText + '"' + ')');
rowMatches.eq(0).parent().parent().parent().css("display", "none");
}
感谢您的帮助!
答案 0 :(得分:1)
我认为这是等效的:
function hideRowContainingText( strText )
{
$('td nobr:contains("' + strText + '")').eq(0).closest('tr').hide();
}