我有一個功能,通過點擊它包含在< thead
>標記中的標題隱藏/顯示錶。點擊時,表格隱藏,剩下的只是標題,通過再次點擊可以取消隱藏表格。Javascript/jquery:無法指定表中的兄弟節點
我有多個表,並且只想使用函數,而不是爲每個表編寫一個表。爲了做到這一點,我試圖傳遞參數(this,this.lastSibling)。由於某種原因,this.lastSibling沒有針對任何對象。我試過了所有可以想到的節點樹的導航方式,但我無法定位到tbody。
我的JavaScript/jQuery的
function ToggleTable(trigger,target){
$(trigger).click(function(){
$(target).toggle();
ToggleTable(trigger,target)
});
}
我的HTML
<table class="format2" >
<thead onmouseover="ToggleTable(this,this.lastSibling)">
<!--Title-->
</thead>
<tbody>
<!--Cells with information in here-->
</tbody>
<!--Note No TFooter Tag-->
</table>
<--Other tables similar to the one above-->
提前感謝!
http://stackoverflow.com/questions/2681581/jquery-how-do-i-check-if-an-element-is-the-last-sibling – zod 2012-07-09 18:59:16
http://stackoverflow.com/questions/2126512/last jquery – zod 2012-07-09 18:59:34