gpt4 book ai didi

javascript - jQuery 切换 tbody

转载 作者:行者123 更新时间:2023-11-30 13:37:29 26 4
gpt4 key购买 nike

我在表格中嵌套表格,并希望在您单击 <th class="folder"> 时切换它们

    $('table').each(function(){
$('th.folder', this).bind('click', function(){
$(this).closest('table').children('tbody').toggle();
});
});

这是一些典型的 HTML:

<table>
<thead>
<tr>
<th>Title</th>
<th class="type">Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<table>
<thead>
<tr>
<th class="folder" colspan="2">Deal flow</th>
</tr>
</thead>
<tbody>
<tr>
<td>item 1</td>
<td>image</td>
</tr>
<tr>
<td>item 2</td>
<td>image</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th class="folder" colspan="2">Rejected deals</th>
</tr>
</thead>
<tbody>
<tr>
<td>item 3</td>
<td>image</td>
</tr>
<tr>
<td>item 4</td>
<td>image</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>

似乎不起作用,我不明白为什么!有什么想法吗?

最佳答案

See Working Example


试试这个:

  $('.folder').bind('click', function(){
$(this).closest('table').children('tbody').toggle();
});

关于javascript - jQuery 切换 tbody,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4163116/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com