javascript ul 上的 jQuery UI 手风琴
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4149171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery UI Accordion on ul
提问by Marty Trenouth
How do I get the jQuery UI Accordionto work when I need to put a wrapper around each element?
当我需要在每个元素周围放置一个包装器时,如何让jQuery UI Accordion工作?
Example HTML:
示例 HTML:
<ul>
<li>
<h3><a href="#">header</a></h3>
<div>
Content goes here
</div>
</li>
<li>
<h3><a href="#">header</a></h3>
<div>
Content goes here
</div>
</li>
</ul>
I just can't seem to get it to work.
我似乎无法让它发挥作用。
回答by Stephen
You cannot make the accordion work with your current markup. Elements must be siblings like this:
您无法使用当前标记使手风琴工作。元素必须是这样的兄弟元素:
<div id="parentAccordionDiv">
<h3><a href="#">header</a></h3>
<div>
Content goes here
</div>
<h3><a href="#">header</a></h3>
<div>
Content goes here
</div>
</div>
<div id="parentAccordionDiv">
<h3><a href="#">header</a></h3>
<div>
Content goes here
</div>
<h3><a href="#">header</a></h3>
<div>
Content goes here
</div>
</div>
I stand corrected. I got an accordion to work fine like this:
我站着纠正。我有一个手风琴可以像这样正常工作:
<script type="text/javascript">
$(function(){
$('#accordion').accordion();
})
</script>
<ul id="accordion">
<li>
<h3><a href="#">header</a></h3>
<div>
Content goes here
</div>
</li>
<li>
<h3><a href="#">header</a></h3>
<div>
Content goes here
</div>
</li>
</ul>

