简体   繁体   English

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

[英]jQuery accordion. Clicking on content of higher section opens lower section

I'm trying to use jQuery accordion, but for some reason when I click on the main content, the next section opens instead. 我正在尝试使用jQuery手风琴,但是由于某些原因,当我单击主要内容时,将改为打开下一部分。 Could you explain to me what I am doing wrong? 你能告诉我我做错了什么吗?

My html is something like this: 我的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> 

在此处输入图片说明

Please refer following code: 请参考以下代码:

 <!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> 

you have a typo in your code. 您的代码中有错字。 it should be <div class="accordion-header"> 它应该是<div class="accordion-header">

You have mistake in header: ".accordion-header" and <div class="accoridon-header"> 您在header: ".accordion-header" <div class="accoridon-header"><div class="accoridon-header">

the accoridon-header and accordion-header not same accoridon-headeraccordion-header不同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM