打开新的时,Jquery切换不关闭行

时间:2012-07-27 19:33:40

标签: jquery

我在尝试让jquery在打开另一个表时关闭表中的空行时遇到问题。我试图使用toggle()无济于事,我知道我只是缺少一些东西。这是我的HTML:

<table class="ProcTable" rules="all" cellpadding="0" cellspacing="0">
   <thead>   
      <tr class="proctablerow">
         <th>Recently Issued Procedures</th>         
      </tr>
   </thead>
   <tbody>
      <tr>
         <td></td>
         <td>Admin</td>
         <td>User Name #1</td>
      </tr>
      <tr>
         <td></td>
         <td>Reader</td>
         <td>User Name #2</td>
      </tr>
      <tr>
         <td></td>
         <td>Reader</td>
         <td>User Name #3</td>
      </tr> 
      </tbody>    
</table>
<table class="ProcTable" rules="all" cellpadding="0" cellspacing="0">
   <thead>   
      <tr class="proctablerow">
         <th>Recently Viewed Procedures</th>         
      </tr>
   </thead>
   <tbody>
      <tr>
         <td></td>
         <td>Admin</td>
         <td>User Name #1</td>
      </tr>
      <tr>
         <td></td>
         <td>Reader</td>
         <td>User Name #2</td>
      </tr>
      <tr>
         <td></td>
         <td>Reader</td>
         <td>User Name #3</td>
      </tr>
      </tbody>      
      </table>
      <table class="ProcTable" rules="all" cellpadding="0" cellspacing="0">
   <thead>   
      <tr class="proctablerow">
         <th>Bookmarked Procedures</th>         
      </tr>
   </thead>
   <tbody>
      <tr>
         <td></td>
         <td>Admin</td>
         <td>User Name #1</td>
      </tr>
      <tr>
         <td></td>
         <td>Reader</td>
         <td>User Name #2</td>
      </tr>
      <tr>
         <td></td>
         <td>Reader</td>
         <td>User Name #3</td>
      </tr>
      </tbody>      
      </table>

      </table>

这是我的jquery代码:

$(document).ready(function() {    
    $("#accordion").accordion( { active: false, collapsible: true });
    $(".ProcTable").accordion( { active: false, collapsible: true, autoHeight: false });  

    $('table.ProcTable tr.proctablerow th') .click(
    function() {
        $(this) .parents('table.ProcTable') .children('tbody') .toggle();
    });

});

有人可以帮我弄清楚如何在打开另一行(手风琴式)时关闭一行。谢谢!

1 个答案:

答案 0 :(得分:0)

$('table.ProcTable tr.proctablerow th').on('click', function() {
    var elm = $(this).parents('table.ProcTable').children('tbody');
    $('table.ProcTable').children('tbody').not(elm).hide();
    elm.toggle();
});

FIDDLE