Javascript 删除/隐藏表格<;tr>;(s) 他们的<;td>;(s) 没有文本

Javascript 删除/隐藏表格<;tr>;(s) 他们的<;td>;(s) 没有文本,javascript,jquery,Javascript,Jquery,请看一看并让我知道如何隐藏或删除动态表中(如果一行中的所有行)为空的所有行?这主要发生在表的末尾,因为我生成了一个包含5行的表,但有时我从数据源只获得3或4行数据 请注意,empty是指文本值,而不是像div这样的html元素 <table style="width:100%"> <tr> <td class="monBox">Jill</td> <td class="monBox">Smith&

请看一看并让我知道如何隐藏或删除动态表中
(如果一行中的所有行)为空的所有行?这主要发生在表的末尾,因为我生成了一个包含5行的表,但有时我从数据源只获得3或4行数据

请注意,empty是指文本值,而不是像div这样的html元素

<table style="width:100%">
    <tr>
        <td class="monBox">Jill</td>
        <td class="monBox">Smith</td>
        <td class="monBox">50</td>
    </tr>
    <tr>
        <td class="monBox">Eve</td>
        <td class="monBox">Jackson</td>
        <td class="monBox">94</td>
    </tr>
    <tr>
        <td class="monBox"></td>
        <td class="monBox"></td>
        <td class="monBox"></td>
    </tr>
    <tr>
        <td class="monBox">Eve</td>
        <td class="monBox">Jackson</td>
        <td class="monBox">94</td>
    </tr>
     <tr>
        <td class="monBox"></td>
        <td class="monBox"></td>
        <td class="monBox"></td>
    </tr>   

</table>

吉尔
史密斯
50
前夕
杰克逊
94
前夕
杰克逊
94

谢谢

试着检查每个tr,检查里面的td元素是否都是空的,就像这样

$('table').find('tr').each (function() {

    var rows = 0;
    var rows_empty = 0;

     $(this).find('td').each (function() {
          rows++;
          if($(this).text().trim() == "")
              rows_empty++;
    }); 

    if(rows === rows_empty)
        $(this).remove();
}); 

试试这个,注意我给了表一个
target的ID

//Loop through rows with empty cells
$("#target tr").has("td:empty").each(function(){
    //hide the row if all cells are empty
    if($(this).find("td").length === $(this).find("td:empty").length){
        $(this).hide();    
   }
});

或者稍微简单一点:

$("#target tr").has("td:empty").each(function(){
    if($(this).find("td:not(:empty)").length === 0){
        $(this).hide();
    }
});
或者更好:

$('#target tr').not(':has(td:not(:empty))).remove()

它根本不检查表单元格就可以工作

$('#target tr').each(function(index,el).   
 { 
    if($.trim($(this).text()) == '')
    {
       $(this).remove();
    }
}
);