【问题标题】:jquery contains helpjquery 包含帮助
【发布时间】:2010-12-20 10:05:42
【问题描述】:

我有一些我想操作的 html。其结构如下:

TEXT_TO_LOOK_FOR

我在这里编写了一个函数来隐藏包含此文本的行,但我只是想知道是否有人可以清理它。我觉得它可能让 jquery 做的工作超出了它的需要。

我知道我可以搜索包含该文本的行,但我希望该函数具有健壮性,以便在其他地方找到该文本时它不会隐藏行。

function hideRowContainingText(strText)
{
    var rowMatches = $('tbody tr td nobr:contains(' + '"' + strText + '"' + ')');
    rowMatches.eq(0).parent().parent().parent().css("display", "none");
}

感谢您的帮助!

【问题讨论】:

  • 我是 jQuery 新手,只是好奇(' + '"' + strText + '"' + ')') 是什么@ 他们需要什么?谢谢

标签: jquery contains


【解决方案1】:

我认为这是等价的:

function hideRowContainingText( strText )
{
    $('td nobr:contains("' + strText + '")').eq(0).closest('tr').hide();
}

【讨论】:

  • 谢谢。正是我想要的。
猜你喜欢
  • 2011-07-12
  • 2011-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多