gpt4 book ai didi

jquery - 使用 jquery 关闭可折叠菜单

转载 作者:太空宇宙 更新时间:2023-11-04 07:45:42 24 4
gpt4 key购买 nike

我试图在使用 jquery 单击时关闭可折叠菜单的内容。下面我附上了 fiddle 以供引用。

<div id="advent">
<i id="arrow" class="fa fa-plus-circle" style="margin-left:40px"></i>
Advent
<div id="expand" style="display:none">Content</div>
</div>

<script>
$('#advent').click(function () {
$("#arrow", this).toggleClass("fa-minus-circle");
$('#expand').show();
if($this.hasClass()){
$('#expand').slideUp();
}
});
</script>

https://jsfiddle.net/5trqxn6t/3/

最佳答案

只需使用 toggle 或 slideToggle

$('#advent').click(function () {
$("#arrow", this).toggleClass("fa-minus-circle");
$('#expand').slideToggle();
});

https://jsfiddle.net/5trqxn6t/5/

关于jquery - 使用 jquery 关闭可折叠菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48155900/

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