jQuery Accordion active by url?

放肆的年华 提交于 2019-12-22 01:19:14

问题


Header script section.

$(document).ready(function(){
    var show_link = '/hr/resitration'; // That is current url.
    var accordion = $("#accordion");
    active = ???? // How to found activ url???
    accordion.accordion({
        header: "h3",
        active: active,
        autoHeight: false
    });
});

in HTML section

<div id="accordion">
    <h3><a href="#">Dashboard</a></h3>
    <div>
        <ul>
            <li><a href="/dashboard/my" >My works</a></li>
            <li><a href="/dashboard/send" >Send works</a></li>
        </ul>
    </div>
    <h3><a href="#">HR</a></h3>
    <div>
        <ul>
            <li><a href="/hr/resitration?add=true" >Add Staff</a></li>
            <li><a href="/hr/resitration" >Staff list</a></li>
            <li>Config
                <ul>
                <li><a href="/hr/schools" >Schools</a></li>
                <li><a href="/hr/role" >Roles</a></li>
                </ul>
            </li>
        </ul>
    </div>
</div>

回答1:


I think this will get you close:

active = accordion.find("a[href="+show_link+"]").parents("h3");



回答2:


var links =  accordion.find("a");
active = links.find("[href=/hr/resitration]").index();


来源:https://stackoverflow.com/questions/4171663/jquery-accordion-active-by-url

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