jQueryUI - Accordion - Setting Active using ID

不羁的心 提交于 2019-12-11 01:56:44

问题


I've checked a number of sites trying to figure this out. However, I have had no luck and figured I would go ahead and make a post on here.

What I am trying to do is setting the Active Accordion depending on ID. Below, is what I am working with.

jQuery Code:

$(function () {
    $("#accordion").accordion({
        collapsible: true,
        header: "h3",
        active: 'h3.content3',
        heightStyle: "content"
    });
});

HTML:

<div id="accordion">
    <h3 class="content1">Content Title</h3>
    <div align="left">
        <p>Content for 1 Goes Here</p>
    </div>

    <h3 class="content2">Content Title</h3>
    <div align="left">
        <p>Content for 2 Goes Here</p>
    </div>

    <h3 class="content3">Content Title</h3>
    <div align="left">
        <p>Content for 3 Goes Here</p>
    </div>
</div>

I hope I explained it well enough, If not, Let me know. I'll try to help ya.


回答1:


Set active based on the h3 index:

active: $('#accordion h3').index($('.content3'))


来源:https://stackoverflow.com/questions/22175515/jqueryui-accordion-setting-active-using-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!