我有一种情况,我在主页面上用链接调用带有Jquery Acoridon的greybox弹出窗口,想知道是否可以在调用它时为acordion设置默认的活动面板。
以下是样本:
在我的主页面中,这是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>
以下是example.php上的Javascript:
$(function() {
$( "#acordion" ).accordion({ active: 0, collapsible: true, autoHeight: false });
这是example.php
的html部分<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作为活动面板打开。只需要在使用链接2或链接3打开时将面板1或面板2设置为活动面板。
答案 0 :(得分: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 });
});