我试图创建一个手风琴,我可以通过一次单击来展开/折叠所有部分。我还需要用户能够打开和关闭一次打开0-n部分的部分。在这里讨论stackoverflow和jQuery论坛中的几个讨论,下面是我提出的解决方案: 我已经实现了每个部分,因为它是自己的手风琴,每个部分都设置为collapsible = true。jquery ui accordion - 多个手风琴展开/折叠所有样式的问题
<html>
<head>
<title>Accordion Test</title>
<script type="text/javascript" src="../scripts/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../scripts/jquery-ui-1.8.4.custom.min.js"></script>
<link rel="stylesheet" href="../_templates/css/jquery-ui-1.8.6.custom.css" type="text/css" />
<link rel="stylesheet" href="../_templates/css/jquery.ui.accordion.css" type="text/css" />
</head>
<body>
<a onClick="expandAll()">Expand All</a>
<br>
<a onClick="collapseAll()">Collapse All</a>
<div id="accordion1" class="accord">
<h5><a href="#">section 1</a></h5>
<div>
section 1 text
</div>
</div>
<!-- orders section -->
<div id="accordion2" class="accord">
<h5><a href="#">section 2</a></h5>
<div>
section 2 text
</div>
</div>
<!-- section 3 -->
<div id="accordion3" class="accord">
<h5><a href="#">section 3</a></h5>
<div>
section 3 text
</div>
</div>
<!-- section 4 -->
<div id="accordion4">
<h5><a href="#">section 4</a></h5>
<div>
section 4 text
</div>
</div>
</body>
</html>
<script type="text/javascript">
$(function() {
$('#accordion1').accordion({
header: 'h5',
collapsible: true,
autoHeight: false
});
});
$(function() {
$('#accordion2').accordion({
header: 'h5',
collapsible: true,
autoHeight: false,
active: false
});
});
$(function() {
$('#accordion3').accordion({
header: 'h5',
collapsible: true,
autoHeight: false,
active: false
});
});
$(function() {
$('#accordion4').accordion({
header: 'h5',
collapsible: true,
autoHeight: false,
active: false
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
})
function expandAll() {
alert("calling expandAll");
$("#accordion1, #accordion2, #accordion3, #accordion4")
.filter(":not(:has(.ui-state-active))")
.accordion("activate", 0);
}
function collapseAll() {
alert("calling collapseAll");
$("#accordion1, #accordion2, #accordion3, #accordion4")
.filter(":has(.ui-state-active)")
.accordion("activate", -1);
}
</script>
我快到的问题是,当我点击的开口部分的标题中,部分预期倒塌,但头仍然有“UI状态为关注焦点”级,直到我点击页面上的其他地方。因此,我在ui中看到的是刚刚关闭的部分的标题与我的悬停效果具有相同的背景颜色,直到我点击其他位置,并且它转变为“默认的,不是焦点”的颜色。
此外,当我使用“全部折叠”链接时,在Firefox中看起来都很棒。在IE中,最后一节标题具有相同的悬停焦点着色。
有什么建议吗?当它关闭时,我是否需要强迫手风琴失去焦点?我将如何实现这一目标?
这不是一个手风琴的解决方案。在样品中使用了多个手风琴。 – jmav 2011-04-12 12:47:30