jquery在td没有文本时隐藏表行

jquery在td没有文本时隐藏表行,jquery,html,css,hide,Jquery,Html,Css,Hide,我试图隐藏表中的行,如果该行中没有文本。如何做到这一点。 到目前为止我试过了 Javascript: $('#tblNodes > tbody > tr').each(function () { if ($td.text() == '') { $(this).hide(); } }); HTML: abc abc 您可以使用.is()和:empty选择器来实现您想要的功能 试试看 试试这个 $('#tblNodes tr').each(func

我试图隐藏表中的行,如果该行中没有文本。如何做到这一点。 到目前为止我试过了

Javascript:

$('#tblNodes > tbody  > tr').each(function () {
    if ($td.text() == '') {
        $(this).hide();
    }
});
HTML:


abc
abc
您可以使用
.is()
:empty
选择器来实现您想要的功能

试试看

试试这个

 $('#tblNodes tr').each(function() {
   $td=$(this).find('td');
    if($td.text() == ''){
      $(this).hide();
    }
 });
试试这个

$('#tblNodes > tbody  > tr').each(function() {
    if($(this).find('td').text() == ''){
    $(this).hide();
    }
});
您可以尝试:

1) 检查表中每个TR中的TD

2) 如果没有文本,请将其“显示”属性设置为“无”

$('#tblNodes tr').each(function() {
   $td=$(this).find('td');
    if($td.text() === ''){
      $(this).css("display", "none");
    }
 });

试试这个:

$('#tblNodes tbody  tr').each(function () {
    if ($(this).find('td').is(':empty')) {
        $(this).hide();
    }
});
试一试


空和检查“”之间的区别是什么?哪一个好?
:empty
将选择没有子元素的所有元素(包括文本节点)。从文件中。两种方法都是一样的..this.hide更好还是this.css.display没有更好?两者都一样,hide();将“显示”属性设置为“无”。但有信息很重要。如果你想使用小动画,你可以使用=>hide(“slow”);或隐藏(1000);
$('#tblNodes tr').each(function() {
   $td=$(this).find('td');
    if($td.text() === ''){
      $(this).css("display", "none");
    }
 });
$('#tblNodes tbody  tr').each(function () {
    if ($(this).find('td').is(':empty')) {
        $(this).hide();
    }
});
$('#tblNodes > tbody  > tr').has('td:empty').hide()
$('#tblNodes > tbody  > tr td:empty').parent().hide()