2013-04-11 125 views
0

我有一张桌子,其中一行有一张儿童桌子。 当点击类“Show”的锚时,我想:显示/隐藏和幻灯片表

  1. 使子表可见...滑动它。
  2. 将锚类从“显示”更改为“隐藏”。

我该怎么做?

我的代码如下:

<table class="Parent"> 
    <tr> 
     <td class="Task"></td> 
     <td>Row1</td> 
    </tr> 
    <tr> 
    <td class="Task"><a class="Show">Show</a></td> 
    <td>Row 2 
     <table class="Child" style="display: none"> 
      <tr><td>Row1</td></tr> 
     <tr><td>Row2</td></tr> 
     </table> 
    </td> 
    </tr> 
</table> 

谢谢!

+0

退房'的slideToggle()'或'隐藏()'和'显示()' – 2013-04-11 17:15:26

回答

1

您需要包裹.Child在一个div,否则将其显示为table-cell,这将影响到幻灯片动画。

$(document).ready(function(){ 
    $('.Show, .Hide').click(function(){ 
     var child = $(this).closest('tr').find('.Child').closest('div'); 

     if($(this).hasClass('Show')){ 
      $(this).removeClass('Show').addClass('Hide').html('Hide'); 
     }else{ 
      $(this).removeClass('Hide').addClass('Show').html('Show'); 
     } 

     child.slideToggle('fast'); 
    }); 
}); 

DEMO(WITH DIV): http://jsfiddle.net/dirtyd77/ppgH9/9/

DEMO(无DIV): http://jsfiddle.net/dirtyd77/ppgH9/8/

+0

嗨,这工作得很好。感谢您的帮助。 – 2013-04-11 23:23:29