jQuery UI手风琴的HTML5标记

时间:2013-03-21 02:50:51

标签: jquery html5 jquery-ui jquery-ui-accordion

我有以下标记,我想使用jQuery UI手风琴,但它不像我在HTML5之前制作的典型手风琴那样呈现。我如何通过使用article / section来获得手风琴?

<article>
    <h1>Accordion</h1>
    <div id="accordion">
        <section>
            <h1><a href="#">Aliquam tincidunt mauris eu risus.</a></h1>
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna.</p>
        </section>
        <section>
            <h1><a href="#">Integer vitae libero ac risus egestas placerat.</a></h1>
            <p>Sed egestas, ante et vulputate volutpat, eros pede semper est, vitae luctus metus libero eu augue. Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus.</p>
        </section>
        <section>
            <h1><a href="#">Fusce lobortis lorem at ipsum semper sagittis.</a></h1>
            <p>Morbi interdum mollis sapien. Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus.</p>
        </section>
    </div>
</article>

在javascript中我使用:

$(document).ready(function (){
    $('#accordion').accordion();    
});

2 个答案:

答案 0 :(得分:3)

我们在JSFiddle中测试了以下代码......

<div id="accordion">
   <article class="std_page_content">
    <a id="#test" href="#test" class="header"><h1>Aliquam tincidunt mauris eu risus</h1></a>
    <section>
           <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna.</p>
        </section>
    <a href="#test" class="header"><h1>Integer vitae libero ac risus egestas placerat.</h1></a>
       <section>
            <p>Sed egestas, ante et vulputate volutpat, eros pede semper est, vitae luctus metus libero eu augue. Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus.</p>
        </section>
       <a href="#test" class="header"><h1>Fusce lobortis lorem at ipsum semper sagittis.</h1></a>
        <section>
            <p>Morbi interdum mollis sapien. Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus.</p>
        </section>
   </article>
</div>

和手风琴代码为 -

$("#accordion").accordion({header : "a.header", heightStyle : "content", 
   /*Allows full collapse*/collapsible: true, 
   /*collapses sections*/ active:false, 
   navigation:true
});

我们的链接是 - http://jsfiddle.net/3tGYB/2/

你可以试试这个......

答案 1 :(得分:2)

作为旁注,您最好使用details and summary元素。