这是我为解释这种情况而创建的代码示例。 它工作得很好,但是当它切换到隐藏 tbody 时,它会产生一种奇怪的效果(首先将 tbody 扩大三到四倍,然后它直接塌陷,当它向下滑动时它也会直接塌陷).
滑下对我来说不是问题,但折叠时是问题。
你能帮帮我吗?
谢谢
代码。
<html>
<head>
<script type="text/javascript">
$(function() {
$(".tblGeneral thead").click(function() {
$(this).next(".tblGeneral tbody").slideToggle("fast");
});
});
</script>
</head>
<body>
<table class="tblGeneral">
<thead>
<tr>
<td colspan="2">Title</td>
</tr>
</thead>
<tbody>
<tr>
<td class="title">Name:</td>
<td>Some name</td>
</tr>
</tbody>
</table>
</body>
最佳答案
嘿,你要应用css
position: relative;
到你的 table ,这应该可以解决问题。
所以在你的情况下,它会是
.tblGeneral { position: relative; }
关于jquery slideToggle奇怪的效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2401065/