2012-09-08 21 views
0

我有一个情况,我打电话给一个灰色的弹出式窗口,带有Jquery Acoridon从主页上的链接,并想知道是否可以在调用它时设置默认的活动面板。是否可以在调用时动态设置Jquery Accordion的活动面板?

下面是示例:

在我的主页,这是HTML:

<a href="example.php" id="1" onclick="return parent.GB_showCenter('Example.', this.href, 400, 600)" target="_blank"> 
Panel 1 
</a> 

<a href="example.php" id="2" onclick="return parent.GB_showCenter('Example.', this.href, 400, 600)" target="_blank"> 
Panel 2 
</a> 

<a href="example.php" id="3" onclick="return parent.GB_showCenter('Example.', this.href, 400, 600)" target="_blank"> 
Panel 3 
</a> 

这里是JavaScript的使用example.php:

$(function() { 
    $("#acordion").accordion({ active: 0, collapsible: true, autoHeight: false }); 

这是例如HTML部分.php

<div id="acordion"> 
    <h3><a href="#">Panel 0</a></h3> 
    <div>Do something @ Panel 1</div> 

    <h3><a href="#">Panel 1</a></h3> 
    <div>Do something @ Panel 2</div> 

    <h3><a href="#">Panel 2</a></h3> 
    <div>Do something @ Panel 3</div> 

</div> 

我将面板0设置为默认活动面板,并且每次打开该页面时都会将面板0作为活动面板打开。只需将面板1或面板2设置为活动面板,同时用链接2或链接3打开。

回答

0

您需要将默认面板值传递给页面,例如,在URL的散列部:

<a href="example.php#1" id="1" onclick="return parent.GB_showCenter('Example.', this.href, 400, 600)" target="_blank"> 
Panel 1 
</a> 

然后,只需使用JavaScript阅读:document.location.hash,并为您的手风琴默认值使用。

$(function() { 
    var hash = document.location.hash; 
    $("#acordion").accordion({ active: hash, collapsible: true, autoHeight: false }); 
}); 
+0

感谢米哈尔,你的答案是诀窍。我首先遇到了麻烦,不得不使用parseInt()和哈希值,现在它的工作方式就像魅力一样。再次感谢。 –

相关问题