链接以打开jQuery手风琴 [英] Link to open jQuery Accordion

查看:90
本文介绍了链接以打开jQuery手风琴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从外部链接打开手风琴div.我看到了"navigation:true"选项,但不确定如何实现.您是否给每个div一个ID并按如下方式调用链接? http://domain.com/link#anchorid

I'm trying to open an accordion div from an external link. I see the "navigation: true" option but I'm not sure how to implement it. Do you give each div an id and call the link like this? http://domain.com/link#anchorid

我是jQuery的新手,请多多包涵.这是我正在使用的代码(如果有帮助的话).

I'm new to jQuery so bear with me. Here is the code I'm using if it helps.

<script type="text/javascript">
    $(function(){
        $("#accordion").accordion({ header: "h2", autoHeight: false, animated: false, navigation: true });
         });
    </script>
<div id="accordion">

<div>
    <h2><a href="#">Services</a></h2>
    <div class="services">
    <p>More information about all of these services</p>
    </div>
</div>

推荐答案

导航选项不适用于面板激活.这是为了告诉用户他们在哪里.

The navigation option isn't for panel activation. It's for telling the user where they are.

使用简化的html代码:

Using simplified html code:

<div id="accordion">

    <div>
        <h2><a href="#services">Services</a></h2>
        <p>More information about all of these services</p>
    </div>

    <div>
        <h2><a href="#about">About</a></h2>
        <p>About us</p>
    </div>

</div>

您将唯一ID放在标题的超链接中

You put the unique ID in the Hyperlink in the title

然后使用jQuery(简体):

Then the jQuery (simplified):

<script type="text/javascript">
    $(function(){
        $("#accordion").accordion({ header: "h2", navigation: true });
     });
</script>

通过"navigation:true",您可以访问www.site.com/#about,这将使"about"面板处于选中状态.对于激活,有两种方法.也许一种方法是获取查询字符串并将其放入jQuery.

The "navigation : true" will enable you to go www.site.com/#about which makes the "about" panel selected. For activation, there are a couple of ways. Perhaps one way is to grab a query string and put it into the jQuery.

使用C#

$("#accordion").accordion("activate", '<%= Request.QueryString["id"] %>');

使用PHP

$("#accordion").accordion("activate", '<?php echo $_GET['id']; ?>');

您可以通过www.site.com?id=2指定哪个面板打开

Which will allow you to specify which panel to open by www.site.com?id=2

这篇关于链接以打开jQuery手风琴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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