2011-09-07 144 views

回答

2

w ^帽子你就已经是接近的工作,但你在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

+0

谢谢@詹姆斯..它工作完美:-) – Sullan

+0

没问题,很高兴我可以帮助:)不要忘记接受帮助你的答案! –

+0

与该代码有一个小问题,该列被删除,如果它的空,这应该发生,只有当该表是空的那一行..你可以建议如何改变它 – Sullan

0

怎么是这样的:

// 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(); 
    } 
}); 
0
$(function() { 
    $('.parentRow').each(function() { 
    if ($(".firstTab", this).text() === '' && $('.secondTab', this).text() === '') 
    { 
     $(this).hide(); 
    } 
    }); 
});