简体   繁体   English

调用时是否可以动态设置Jquery Accordion的活动面板?

[英]Is it possible to set active panel of Jquery Accordion dynamically while calling?

I have a situation where I am calling a greybox popup window with Jquery Acoridon from main page with links and would like to know if it is possible to set default active panel for acordion while calling it. 我有一种情况,我从带有链接的主页调用带有Jquery Acoridon的greybox弹出窗口,并且想知道是否有可能在调用它时为acordion设置默认的活动面板。

Here is sample: 这是示例:

In my main page this is the HTML: 在我的主页上,这是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>

Here is the Javascript on example.php: 这是example.php上的Javascript:

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

This is html part of example.php 这是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>

I set panel 0 as default active panel and this opens panel 0 as active panel whenever I open that page. 我将面板0设置为默认活动面板,并在每次打开该页面时将面板0打开为活动面板。 Just want to set panel 1 or panel 2 as active panel while opening with link 2 or link 3. 只想在通过链接2或链接3打开时将面板1或面板2设置为活动面板。

You need to pass default panel value to the page, eg in hash part of url: 您需要将默认面板值传递给页面,例如在url的哈希部分:

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

Then just read it with javascript: document.location.hash , and use as default value for your accordion. 然后,只需使用javascript: document.location.hash阅读,并将其用作手风琴的默认值即可。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM