为什么你需要使用2类,当你只能使用一个?只是要告诉你哪些是开放的或不开放的。
$("h3").click(function() {
var $div = $(this).siblings('.head'); // cache the relative divs
var len = $div.filter('.active').length; // get how many are active
var $topic = $(".topics", $(this).parent()); // topics relative to element
if (len == $div.length) { // if all are active
$div.removeClass('active'); // remove class active
$topic.slideUp(350); // slideup
} else {
$div.addClass('active'); // else add active to all
$topic.slideDown(350) // slide down
}
});
$(".head").click(function() {
var $el = $(this); // cache this
if ($el.hasClass("active")) {
$el.removeClass("active").next().slideUp(350);
} else {
$el.addClass("active").next().slideDown(350);
};
});
http://jsfiddle.net/pmsJa/
真棒太感谢你了!我对jQuery非常陌生。有时我会让事情知道有更简单的方法,但我只是不知道要做到这一点。非常感谢 – user1842315
@ user1842315不客气:)希望这是你正在寻找的..也检查绿色复选标记,如果这回答了你的问题 –