问题
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