有一個問答系統,答案開始隱藏,然後當問題被點擊時,答案就會滑落。這工作正常,但我希望它,如果再次點擊問題,答案滑回。目前它只是忽略了這個命令。刪除/添加類正在工作,所以我不能認爲它可以是什麼?p標籤會滑落,但不會向上滑動
HTML: <h2 class="traverse">What subjects are covered in the Core Knowledge Sequence UK?</h2> <p class="traversing">The Core Knowledge Sequence UK is a guideline of the fundamental skills and content to cover in English, maths, history and geography, science, music and visual arts.</p>
的Jquery:
$(".traverse").click(function(){
$(this).next("p.traversing").slideDown();
$(this).removeClass('traverse');
$(this).addClass('traversed');
});
$(".traversed").click(function(){
$(this).next("p.traversing").slideUp();
$(this).removeClass('traversed');
$(this).addClass('traverse');
});
你也可以使用'live'點擊事件 – thecodeparadox