2012-09-19 19 views
0

下面是HTML結構顯示/隱藏所有TR-S內部表

<table class="views-table cols-3"> 
     <caption> 
     <h2>LINK(which will hide/show all trs in this table)</h2> 
     </caption> 
    <thead> 
    <tbody> 
    ... 
    </tbody> 
</table> 

此表與同一類重複ñ倍。請幫助使用js或jquery腳本,在鏈接被點擊的表格中隱藏/顯示所有tr -s或整個<tbody>

回答

-1

在jQuery中:

(jQuery.noConflict())(function($){ 
    $('.views-table cols-3 h2').click(function(){ 
     if($(this).parent('.views-table').find('TBODY > TR')[0].is(':visible')) { 
      $(this).parent('.views-table').find('TBODY > TR').hide(); 
     } else { 
      $(this).parent('.views-table').find('TBODY > TR').show(); 
     } 
    }); 
}); 
+1

這並不認爲該表與同級別重複n次。 –

2
$(".views-table h2").click(function(){ 
     var table = $(this).parents("table"); 
     var tbody = table.children("tbody"); 
     if(tbody.is(':visible')){ 
       tbody.hide(); 
     }else{ 
      tbody.show(); 
     } 

}); 

嘗試此鏈接http://jsfiddle.net/wFcpP/8/

+0

我真的很抱歉,請看看我的評論shaun5 – Martin

3
$('.views-table h2').click(function() { 
     $(this).closest('table').find('tbody').toggle(); 
}); 
+0

我真的很抱歉,但似乎我的cms不允許我使用jq腳本。你會寫一個js等效函數嗎?我將這些代碼粘貼在:視圖>標題>全局:文本區域,但由於某種原因,它不加載jq。但它加載JS(我用alert()測試它)。 – Martin

+0

我不知道'cms'是什麼,'Views> Header> Global:Text area'是什麼,並且很少在沒有jQuery的情況下操作DOM,因此您可能需要找到其他人(或者找出爲什麼jq isn 't loading)... – shaun5