如果行包含空列,请隐藏行 [英] Hide row if it contains empty columns

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

问题描述

我有一个包含几行的表,每行有两列,第一列将包含标题,第二列将具有相应的值。有时,右边的单元格可能没有值,因此它不会有意义只有标题..没有价值..我可以隐藏左侧单元格上的标题,右侧或整行本身没有价值。

I have a table with a couple of rows, each row with two columns, the first column will hold title and second column will have the respective values.sometimes, cells in the right may not have values, so it doesn't make sense to have just the title..with no value.. I can either hide the title on the left cell that has no value on the right or the whole row itself.

我已经提出了这个但它没有工作..

I have come up with this but its not working..

    $('.EventDetail tr').each(function(){      
        if(!$('td:not(:empty)',this).length)         
        $(this).hide();
}); 

这是表格。我想知道标签是否有任何区别。或者其中一个有一个类而另一个没有..应该导致它不起作用?

Here is the table. I am wondering if tag is making any difference. OR one of the has a class and the other one don't ..should that be causing it to not work?

<table cellpadding="10" class ="EventDetail">
    <tr>
        <td class="TableFields"><em>Who Should Enroll?:</em></td>
        <td>Everyone 18 and older who would like to attend</td>
    </tr>       
    <tr>
        <td class="TableFields"><em>Handicapped Access:</em></td>
        <td>Yes</td>
    </tr>
    <tr>
        <td class="TableFields"><em>Parking Notes:</em></td>
        <td></td>
    </tr>
    <tr>
        <td class="TableFields"><em>Instructor:</em></td>
        <td>John Filler</td>
    </tr>
</table>

所以没有停车注释信息,所以我想要隐藏包含标题的左侧单元格停车笔记。

So there is no parking notes info, so I want to hide the left cell that contains the title 'Parking Notes".

推荐答案

我认为这样可行:

$('.EventDetail tr').has('td:nth-child(2):empty').hide()

您可以在 jsFiddle 上试用。

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

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