2013-08-20 57 views
0
<table id="main_table">  
     <tr style="background-color:green; color:white"> 
      <td class="flip"> Section 1 </td> 
     </tr> 
    <tr> 
     <td> 
      <table class="section"> 
       <tr> 
        <td>item 111</td> 
        <td>item 112</td> 
        <td>item 113</td> 
        <td>item 114</td> 
       </tr> 
      </table> 
     </td> 
    </tr> 
</table> 

$('.flip').click(function() { 
    $(this) 
     .closest('table') 
     .next('.section') 
     .toggle('fast'); 
}); 

有人可以幫我糾正上面的代碼 我試過的slideToggle但不知道爲什麼它不工作的jQuery的slideToggle桌子上

感謝

回答

0

section元素是下一個tr元素的子

$('.flip').click(function() { 
    $(this) 
     .closest('tr').next() 
     .find('.section') 
     .toggle('fast'); 
}); 

演示:Fiddle

1

您可以使用tr代替table獲得下一行並使用find()獲得.section

$('.flip').click(function() { 
    $(this) 
     .closest('tr') 
     .next('tr') 
     .find('.section') 
     .toggle('fast'); 
}); 
+0

他改變了答案,反正很多人都可以給相同的答案,時間差異很小 – Adil

0

試試這個

$('.flip').on('click',function() { 
$(this) 
.closest('tr').next('tr') 
.find('.section') 
.toggle(200); 
}); 

Reference