我在这里找到了这段代码:https://jqueryui.com/accordion/#collapsible
但我不明白如何在此代码中执行data-collapsed =“false”, 这是我的完整代码:
<!DOCTYPE html>
<html lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>jQuery UI Accordion - Collapse content</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#accordion" ).accordion({
collapsible: true
});
});
</script>
</head>
<body>
<div role="tablist" class="ui-accordion ui-widget ui-helper-reset" id="accordion">
<h3 tabindex="0" data-collapsed="false" aria-expanded="false" aria-selected="false" aria-controls="ui-id-2" id="ui-id-1" role="tab" class="ui-accordion-header ui-state-default ui-accordion-icons ui-state-focus ui-corner-all"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span>Section 1</h3>
<div aria-hidden="true" role="tabpanel" aria-labelledby="ui-id-1" id="ui-id-2" style="display: none; height: 105px;" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom">
<p>Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam.
Integer ut neque. Vivamus nisi metus, molestie vel, gravida in,
condimentum sit amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi.
Proin viverra leo ut odio. Curabitur malesuada. Vestibulum a velit eu
ante scelerisque vulputate.</p>
</div>
<h3 tabindex="-1" aria-expanded="false" aria-selected="false" aria-controls="ui-id-4" id="ui-id-3" role="tab" class="ui-accordion-header ui-state-default ui-corner-all ui-accordion-icons"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span>Section 2</h3>
<div aria-hidden="true" role="tabpanel" aria-labelledby="ui-id-3" id="ui-id-4" style="display: none; height: 105px;" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom">
<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 tabindex="-1" aria-expanded="false" aria-selected="false" aria-controls="ui-id-6" id="ui-id-5" role="tab" class="ui-accordion-header ui-state-default ui-corner-all ui-accordion-icons"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span>Section 3</h3>
<div aria-hidden="true" role="tabpanel" aria-labelledby="ui-id-5" id="ui-id-6" style="display: none; height: 105px;" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom">
<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 tabindex="-1" aria-expanded="false" aria-selected="false" aria-controls="ui-id-8" id="ui-id-7" role="tab" class="ui-accordion-header ui-state-default ui-corner-all ui-accordion-icons"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span>Section 4</h3>
<div aria-hidden="true" role="tabpanel" aria-labelledby="ui-id-7" id="ui-id-8" style="display: none; height: 105px;" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom">
<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>
问题是我每次只是重新加载它显示的页面:
但是想要这样:
请帮帮我,谢谢你。
答案 0 :(得分:2)
您根本不需要修改任何HTML,因为jQueryUI accordion具有0
属性来确定在加载时展开哪个面板。默认情况下,它是false
- 第一个面板。将其设置为$("#accordion").accordion({
collapsible: true,
active: false
});
以默认全部折叠:
[<NamedUnionCases "Icon">]
type IconName =
| Aaabattery
| Abacus
[<NamedUnionCases>]
type Size =
| H1
| H2
| H3
| H4
| H5
type Icon = {title:string; name:IconName; size:Size; updated:DateTime; }
Icon {title = "hello";
name = Aaabattery;
size = H1;
updated = 11/06/2015 3:18:29 p. m.;}
&GT; Active property docs