用jQuery清除5个空TD [英] Clear 5 empty TDs with Jquery
问题描述
我有一个动态表正在填充,我知道我不应该这样做,但是如何连续查找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屋!