爲什麼這兩個函數有點奇怪的行爲,當我點擊thead時,tbody展開然後崩潰。jQuery函數的奇怪行爲
在第二個函數可以做一些測試,添加警報給if,else語句,但它只進入if語句,所以它只會滑動。
我注意到的另一件事是,當tbody中只有一行時,它工作正常。爲什麼?
我也嘗試添加返回false,沒有任何功能,它不會被調用兩次或任何其他地方。
我將不勝感激,如果我能得到一些解決這個問題。
謝謝。
Function 1
$(function() {
$("table.section thead").click(function() {
$(this).next("table.section tbody").slideToggle("slow");
});
});
Function 2
$(function() {
$("table.section thead").click(function() {
var body = $(this).next("table.section tbody");
if (body.is(":visible"))
body.slideUp("slow");
else
body.slideDown("slow");
});
});
UPDATE 表
<table>
<thead>
<tr><td>heading></td></tr>
</thead>
<tbody>
<tr><td>content1</td></tr>
<tr><td>content2</td></tr>
</tbody>
</table>
這兩個函數是同時綁定還是這兩次嘗試做同樣的事情? – Sorpigal 2010-03-10 13:07:34
你能告訴我們你的桌子嗎? – hallie 2010-03-10 13:08:29
OP重複問題 http://stackoverflow.com/questions/2415999/jquery-help-converting-simple-function-please-help/2416034#2416034 – 2010-03-10 13:09:34