【发布时间】:2011-09-07 08:28:44
【问题描述】:
有一个 2 列的表,其中每列由另一个包含一些数据的表组成,如果两列都是空的,我想要做的是隐藏整行.. 任何人都可以在上面分享一些输入..
提前致谢
【问题讨论】:
有一个 2 列的表,其中每列由另一个包含一些数据的表组成,如果两列都是空的,我想要做的是隐藏整行.. 任何人都可以在上面分享一些输入..
提前致谢
【问题讨论】:
您已经接近工作,但您的 if 声明中有错误:
if ($(this).find('.firstTab').text() == '' && (this).find('.secondTab').text() == '')
请注意第二个条件中缺少的$。如果.firstTab 和.secondTab 元素中有空格,它也会失败。就个人而言,我会稍微不同地编写代码,使用filter 方法和.trim 删除内容开头或结尾的任何空白:
$(".parentRow > td").filter(function() {
return $.trim($(this).find(".firstTab").text) == "" && $.trim($(this).find(".secondTab").text()) == "";
}).remove();
这是上述代码的live example。
【讨论】:
$(function() {
$('.parentRow').each(function() {
if ($(".firstTab", this).text() === '' && $('.secondTab', this).text() === '')
{
$(this).hide();
}
});
});
【讨论】:
这样的事情怎么样:
// loop through each row...
$('.parentRow').each(function() {
var rowEmpty = true;
// check each cell in the row to see if it's got anything in it
$($this).find('td').each(function(){
if($(this).html() != "")
{
rowEmpty = false;
}
});
// if the row was empty, hide it
if(rowEmpty)
{
$(this).hide();
}
});
【讨论】: