jQuery UI Accordion在启动时打开多个标签

时间:2015-02-17 22:06:42

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

如何在手风琴开启时打开多个标签?像这样

$( ".selector" ).accordion( "option", "active", 2 );
$( ".selector" ).accordion( "option", "active", 3 );

还是喜欢这个?

$( "#accordion" ).accordion({
  active: 1
  active: 2
});

2 个答案:

答案 0 :(得分:0)

    You can use multiAccordion and it goes like this:
    // this will make the second tab by default opened (index starts from 0)
    $('.selector').multiAccordion({active: 1 }); 

    // [ OR ]
    // supports multiple tabs to be opened by default
    $('.selector').multiAccordion({active: [1, 2, 3] }); 

   // you can also set active:false if you don't want any tab to be opened by default
   $('.selector').multiAccordion({active: false });

   // show all tabs
   $('.selector').multiAccordion({active: 'all' });

   // hide all tabs
   $('.selector').multiAccordion({active: 'none' });

   // you can set the options as any jQuery UI plugin using option method
   $('.selector').multiAccordion('option', 'active', 'all');

答案 1 :(得分:0)

试试这个,

<强> JS

 $("#accordion > div").accordion({ header: "h2", collapsible: true });

<强> HTML

<div id="accordion">
    <div>
        <h2><a href="#">First</a></h2>
        <div>First Secton of hello world.</div>
    </div>
    <div>
        <h2><a href="#">Second</a></h2>
        <div>Second Secton of hello world.</div>
    </div>
    <div>
        <h2><a href="#">Third</a></h2>
        <div>Third Secton of hello world.</div>
    </div>
    <div>
        <h2><a href="#">Fourth</a></h2>
        <div>Forth Secton of hello world.</div>
    </div>
</div>

fiddle

中的工作示例