手风琴 - 如何不扩展第一项?

时间:2015-02-11 15:44:04

标签: javascript jquery jquery-ui-accordion

我正在使用手风琴"功能"基于此:http://jqueryui.com/accordion/#collapsible

我唯一的问题是默认情况下第一个部分是打开的,我希望每个部分都关闭,直到访问者按下它们。

有人知道如何解决这个问题吗?

代码:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#accordion" ).accordion({
collapsible: true
});
});
</script>
</head>
<body>
<div id="accordion">
<h3>Section 1</h3>
<div>
<p><img src="https://placekitten.com/g/200/300"></p>
</div>
<h3>Section 2</h3>
<div>
<p>Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In suscipit faucibus urna. </p>
</div>
<h3>Section 3</h3>
<div>
<p>Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis. Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui. </p>
<ul>
<li>List item one</li>
<li>List item two</li>
<li>List item three</li>
</ul>
</div>
<h3>Section 4</h3>
<div>
<p>Cras dictum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia mauris vel est. </p><p>Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </p>
</div>
</div>
</body>
</html>

4 个答案:

答案 0 :(得分:1)

您应该将active选项设置为false

$( "#accordion" ).accordion({
  collapsible: true,
  active: false
});

答案 1 :(得分:1)

初始化accordion时,将active属性设置为false。这将关闭所有面板:

$('#accordion').accordion({
    collapsible: true,
    active: false
});

答案 2 :(得分:1)

$("#accordion").accordion({ 
         collapsible: true, 
         active: false 
});

active:false将关闭手风琴

其他读者请注意:您需要"collapsible: true"才能"active: false"工作。

答案 3 :(得分:1)

如果您在询问

之前阅读the api,也许会有所帮助
$( "#accordion" ).accordion({
    collapsible: true,
    active: false
});