繁体   English   中英

jQuery如果表中存在特定文本,则隐藏其行的第一个td

[英]jQuery if specific text exists in table hide first td of his row

我想知道如何解决以下问题:我有一个包含几行的表。 我想要的是:检查是否存在特定文本,如果这样,则仅 “隐藏” 该行的第一个TD。

这是我的工作jsfiddle

到目前为止,这是我的JS代码:

var $existingText = $('#myTable');
  if ($existingText.length); {
    if ($existingText.text().replace(/\s+/g, '') === "expired") {
    $(this).parents("tr td:first-child").css('display','none');
  }
};

这应该工作

$('#myTable td:contains(expired)').siblings('td:first-child').hide();

小提琴

这将在这里工作

$existingText.find('tr').each(function(){
    if($(this).text().indexOf('expired') > -1){
        $(this).find('td:first-child').hide()
    }
})

演示

这是工作:

$("tr:has(td:contains('expired'))").each(function () {
    $(this).find("td:first").hide();
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM