如果所有tds为空,则隐藏表行 [英] hide table row if all tds are empty

查看:87
本文介绍了如果所有tds为空,则隐藏表行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种简单的方法,而无需每个循环.

Is there an easy way to do this without a each loop.

我想隐藏整个<tr>,但前提是它的所有<td>都为空白. 该表是动态生成的,因此空白行可以在任何地方.

I want to hide the entire <tr> but only if a all its <td>s are blank. The table is dynamically generated so the blank rows could be any where.

$('#table1 tr:has(td):empty').remove();

HTML

<table id="table1">
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr >
<td></td>
<td></td>
<td></td>
</tr>
...
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
</table>

推荐答案

如果要使用它们,可以按照以下步骤操作:

If you want to use each, you can do it like:

$('#table1 tr').each(function() {
    if ($(this).find('td:empty').length) $(this).remove();
});​

jsFiddle示例

jsFiddle example

这篇关于如果所有tds为空,则隐藏表行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆