jfiddle:http://jsfiddle.net/ZmDs2/1/ 您好,我正在尝试折叠其他父项,同时使用 jQuery 切换仅打开一项。
我试过了
var index = $(this).index();
$('.togglebox').eq(index).slideToggle("fast").siblings('.togglebox').hide();
希望大家帮忙.. 谢谢
最佳答案
我将 javascript 更改为 this :
$(document).ready(function(){
//Hide the tooglebox when page load
var current, toggleBoxes = $(".togglebox").hide();
//slide up and down when click over heading 2
$("h3").click(function(){
current = $(this).next(".togglebox");
toggleBoxes.not(current).slideUp('fast');
current.slideDown("fast");
});
});
我只是用“togglebox”类保存所有元素,并在执行幻灯片切换动画之前折叠它们。
关于javascript - jQuery:切换--> 仅打开一项并折叠其他同级项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6902798/