我在尝试让 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();
});
});
有人可以帮我弄清楚如何在打开另一行的同时关闭一行(手风琴风格)。谢谢!