如何从不同页面链接到特定的手风琴部分? [英] How to link to specific accordion section from different page?

查看:86
本文介绍了如何从不同页面链接到特定的手风琴部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功使用Soh Tanaka的简单的手风琴教程.我希望能够从另一个页面链接到特定的手风琴部分,但是我不确定如何做到这一点.任何帮助将不胜感激,因为我没有太多运气找到本教程特有的帮助.谢谢!

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
});

推荐答案

您应该真正使用 JQuery UI手风琴.然后,如果您希望能够通过脚本选择某个手风琴部分,则可以使用以下内容:

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)

使用此代码,一旦创建了基于id为"myAccordion"的标签的手风琴元素,就可以选择第一页(即索引为0).要选择第二页,可以为最后一个参数传递1,依此类推.

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.

这篇关于如何从不同页面链接到特定的手风琴部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆