在JQuery中独立切换两行

时间:2012-05-30 15:44:31

标签: php jquery

如何独立切换同一个表中的两行。目前我有两个主要行,每个主行包含一些其他行,当我点击任何一行时,主行都切换到如何独立切换它们?

我的HTMl和javascript是

<table id="sort">
    <tr class="nodrag nodrop">
       <td colspan=3><strong><a style="cursor:pointer;" class="toggle">Group 1</a></strong></td>
       <td style="text-align: right;"><a class="button3" href="#" ><span> Edit </span></a> <a class="button3" href="#" ><span> Delete </span></a></td>
   </tr>
        <tr id="1" class="tr_group" style='display:none;'>
            <td style="width:10px;" class="dragHandle">&nbsp;</td>
            <td><a href=# style="margin-left: 20px;">Umair Iqbal</a></td>
            <td><span style="font-size: 12px; color: #999; line-height: 100%;">A Student at TUM</span></td>
            <td style="text-align: right;"><a class="button3" href="#" ><span> Edit </span></a> <a class="button3" href="#" ><span> Delete </span></a></td>
        </tr>
        <tr id="2" class="tr_group" style='display:none;'>
            <td style="width:10px;" class="dragHandle">&nbsp;</td>
            <td><a href=# style="margin-left: 20px;">Faryal Khan</a></td>
            <td><span style="font-size: 12px; color: #999; line-height: 100%;">A Doctor at KMC</span></td>
            <td style="text-align: right;"><a class="button3" href="#" ><span> Edit </span></a> <a class="button3" href="#" ><span> Delete </span></a></td>
        </tr> 

  <tr class="nodrag nodrop">
     <td colspan=3><strong><a style="cursor:pointer;" class="toggle">Group 2</a></strong></td>
     <td style="text-align: right;"><a class="button3" href="#" ><span> Edit </span></a> <a class="button3" href="#" ><span> Delete </span></a></td>
  </tr>
        <tr id="1" class="tr_group" style='display:none;'>
            <td style="width:10px;" class="dragHandle">&nbsp;</td>
            <td><a href=# style="margin-left: 20px;">Umair Iqbal</a></td>
            <td><span style="font-size: 12px; color: #999; line-height: 100%;">A Student at TUM</span></td>
            <td style="text-align: right;"><a class="button3" href="#" ><span> Edit </span></a> <a class="button3" href="#" ><span> Delete </span></a></td>
        </tr>
        <tr id="2" class="tr_group" style='display:none;'>
            <td style="width:10px;" class="dragHandle">&nbsp;</td>
            <td><a href=# style="margin-left: 20px;">Faryal Khan</a></td>
            <td><span style="font-size: 12px; color: #999; line-height: 100%;">A Doctor at KMC</span></td>
            <td style="text-align: right;"><a class="button3" href="#" ><span> Edit </span></a> <a class="button3" href="#" ><span> Delete </span></a></td>
        </tr> 
</table>

jQuery是

<script>
$(".toggle").click(function () {
$(".tr_group").slideToggle('slow');
});    
</script>

1 个答案:

答案 0 :(得分:0)

根据点击的元素选择下一组tr元素。

$(".toggle").click(function(){
    $(this).closest('tr').nextUntil(":not(.tr_group)").slideToggle('slow');
});