2011-09-07 147 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(); 
    } 
    }); 
});