gpt4 book ai didi

javascript - jquery slidetoggle 不会保持打开状态

转载 作者:行者123 更新时间:2023-11-28 13:25:28 25 4
gpt4 key购买 nike

我正在尝试在无序列表上创建 jquery slidetoggle 效果。它会打开,但会立即滑回。我无法确定它是我的 css 还是我的 jquery。顺便说一句,出于某种原因,我无法使用我的 jsfiddle 进行此操作,因此 jsfiddle 只是我的 css、html 和 jquery 的 View 。这是我正在使用的 jquery:

function accordionLoad() {

$(".accordion-header").removeClass("expanded");
$(".accordion-content").hide();

$(".accordion-header").bind("click", function(){
$(this).toggleClass("expanded");
$(this).next(".accordion-content").slideToggle();
})

$(".expand-all").bind("click",function(){
$(this).siblings(".accordion").find(".accordion-content").slideDown();
$(this).siblings(".accordion").find(".accordion-header").addClass("expanded");
})

$(".collapse-all").bind("click",function(){
$(this).siblings(".accordion").find(".accordion-content").slideUp();
$(this).siblings(".accordion").find(".accordion-header").removeClass("expanded");
})
}

$(document).ready(function(){
accordionLoad();
});

和 html..

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
<meta name="Microsoft Theme" content="HDRDefault 1011, default" />

</head>
<body>
<div class="container">
<div class="expand-all">Expand All</div><div class="collapse-all">Collapse All</div>
<UL class="accordion">
<LI class="accordion-item">
<DIV class="accordion-header">Question2</DIV>
<DIV class="accordion-content">
<DIV class="Externa">Answer2..Answer2..Answer2..Answer2..Answer2..Answer2..Answer2..</DIV>
</DIV>
</LI>

<LI class="accordion-item">
<DIV class="accordion-header">Question12</DIV>
<DIV class="accordion-content">
<DIV class="Externa">Answer12..Answer12..Answer12..Answer12..Answer12..Answer12..Answer12..</DIV>
</DIV>
</LI>
</UL>
</div>
</body>
</html>

这是 jsfiddle: http://jsfiddle.net/9CNeX/8/

最佳答案

看这个例子...

jsfiddle

$('.accordion-header').on('click', function(e){
$(this).next().slideToggle();
});

问候。

关于javascript - jquery slidetoggle 不会保持打开状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14225500/

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