用jQuery清除5个空TD [英] Clear 5 empty TDs with Jquery

查看:270
本文介绍了用jQuery清除5个空TD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态表正在填充,我知道我不应该这样做,但是如何连续查找5个空TD并隐藏它们呢?因此,如果行包含5个空TD,请不要显示TD.

I have a dynamic table being filled, and I know I shouldn't do it this way, but how would you go about finding 5 empty TDs in a row, and hiding them? So, if row contains 5 empty TDs, do not show the TDs.

我想删除DOM中<td></td><td></td><td></td><td></td><td></td>的每个实例.不只是第一个.

I want to remove every instance of <td></td><td></td><td></td><td></td><td></td> in the DOM. Not just the first.

我只希望5个空的TD消失,而不是所有空的TD

I just want the 5 empty TDs to go away, not all empty TDs

推荐答案

您可以使用:empty选择器:

$('#yourtable tr td').filter(':empty').hide();

如果要删除具有5个空的td元素的tr元素,则可以使用filter方法:

If you want to remove tr elements that have 5 empty td elements, you can use filter method:

$('#yourtable tr').filter(function(){
   return $(this).find('td:empty').length === 5
}).remove()


如果只想删除前5个空td元素,则可以使用slice方法:


If you want to remove only first 5 empty td elements, you can use slice method:

$('#yourtable tr td').filter(':empty').slice(0, 5).remove();

这篇关于用jQuery清除5个空TD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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