gpt4 book ai didi

javascript - 一次展开/折叠一个

转载 作者:行者123 更新时间:2023-12-03 02:52:33 25 4
gpt4 key购买 nike

如何一次展开一个元素并关闭其他元素?当单击一次打开一个时...

谢谢!

jQuery(document).ready(function($) {
$(".se-q").click( function () {
var container = $(this).parents(".se-c");
var answer = container.find(".se-a");
var trigger = container.find(".se-t");
answer.slideToggle(200);
if (trigger.hasClass("se-o")) {
trigger.removeClass("se-o");
}
else {
trigger.addClass("se-o");
}
})
});

最佳答案

您可以使用 .not()removeClass()toggleClass();

jQuery(document).ready(function($) {
$(".se-q").click( function () {
var container = $(this).parents(".se-c");
var answer = container.find(".se-a");
var trigger = container.find(".se-t");
answer.slideToggle(200);
$('.se-t').not(trigger).removeClass('se-o'); // remove the class from all .se-t element but not this one(container.find(".se-t"))
trigger.toggleClass("se-o"); // toggle class for this(container.find(".se-t"))
})
});

Note: you can catch the point from my code .. but actually you need to provide your html code .. what I got from your code its question/answer script .. so you may need to toggle answer as well

对于answer,您可以在answer.slideToggle(200);之前使用下一行

$('.se-a').not(answer).slideUp(200);

关于javascript - 一次展开/折叠一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47783282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com