jQuery手风琴。单击较高部分的内容将打开较低部分

时间:2016-03-10 12:59:48

标签: javascript jquery html

我试图使用jQuery手风琴,但出于某种原因,当我点击主要内容时,下一部分会打开。你能解释一下我做错了吗?

我的HTML是这样的:



jQuery(".wrap").accordion({
  header: ".accordion-header",
  active: false,
  collapsible: true
});

<ul id="accordion">
  <li class="wrap">
    <div class="accordion-header">
      <a>
        <span>My title</span>
      </a>
    </div>
    <div class="container1">
      <div class="container2">
        <div>Some stuff</div>
      </div>
    </div>
  </li>

  <li class="wrap">
    <div class="accordion-header">
      <a>
        <span>My title</span>
      </a>
    </div>
    <div class="container1">
      <div class="container2">
        <div>Some stuff</div>
      </div>
    </div>
  </li>
</ul>
&#13;
&#13;
&#13;

enter image description here

3 个答案:

答案 0 :(得分:1)

请参阅以下代码:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Accordion - Default functionality</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();
  });
  </script>
</head>
<body>
 
<div id="accordion">
  <h3>Section 1</h3>
  <div>
    <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>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>

答案 1 :(得分:0)

你的代码中有拼写错误。它应该是<div class="accordion-header">

答案 2 :(得分:0)

header: ".accordion-header"你错了 和<div class="accoridon-header">

accoridon-headeraccordion-header不一样