Collapse - 默认打开手风琴第一个元素

Collapse - accordion first element opened by default

我正在使用 Collapse "Accordion"。当我的页面加载时,第一个折叠默认打开,请建议使其默认关闭的方法!!

感谢任何帮助。感谢帮助!!

<link href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"></link>
<link href="/resources/demos/style.css" rel="stylesheet"></link>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<div id="accordion">
  <h3>
    Click Here for answer:)</h3>
  <div style color: "red;">
    <b>Answer: </b>206 Bones
  </div>
</div>


<script>
  $(function() {
    $("#accordion").accordion({
      collapsible: true
    });
  });
</script>

请使用这个。

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

你必须使用这个 属性:

  active: false

下面是一个工作示例:

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />

</head>
<body>
<link href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"></link>
  <link href="/resources/demos/style.css" rel="stylesheet"></link>
<div id="accordion">
<h3>
Click Here for answer:)</h3>
<div style color:"red;">
<b>Answer: </b>206 Bones
  </div></div>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#accordion" ).accordion({
 collapsible: true,
       active: false
    });
  } );
  </script>
</body>
</html>

这样就可以了

$("#accordion").accordion({ collapsible:true, 活跃:假 });