How to link to specific accordion section from different page?

坚强是说给别人听的谎言 提交于 2020-01-17 03:56:05

问题


I have successfully built a JQuery accordion using Soh Tanaka's Simple Accordion tutorial. I would like to be able to link to a specific accordion section from another page but I'm not sure how to do this. Any help would be greatly appreciated as I haven't had much luck finding any help specific to this tutorial. Thanks!

HTML:

<h2 class="acc_trigger"><a href="#">Web Design &amp; Development</a></h2>
<div class="acc_container">
<div class="block">
<!--Content Goes Here-->
</div>
</div>

JQuery:

//Set default open/close settings
$('.acc_container').hide(); //Hide/close all containers
$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

//On Click
$('.acc_trigger').click(function(){
if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
    $('.acc_trigger').removeClass('active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
    $(this).toggleClass('active').next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
}
return false; //Prevent the browser jump to the link anchor
});

回答1:


You should really use JQuery UI accordion. Then if what you want is to be able to select a certain accordion section by script you can use the following:

    $('#myAccordion').accordion("option", "active", 0)

With this code, once you have created an accordion element built on a tag with id "myAccordion", you select the first page (namely, indexed with 0). To select the second page you can pass 1 for the last parameter and so on.



来源:https://stackoverflow.com/questions/6044035/how-to-link-to-specific-accordion-section-from-different-page

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