jQuery手风琴-链接以打开某些div [英] jQuery accordion - link to open certain div

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

问题描述

我正在做一个噩梦,试图使它正常工作(并且看过其他帖子,但仍然有问题).

I am having a nightmare trying to get this working (and have looked at other posts but am still having an issue).

基本上我有这样的链接:

Basically I have a link like this:

/test.php#bob

在test.php上,我有这个:

on test.php I have this:

<div class="accordion">
 <h2>Customer care</h2>
 <div>
  <p>xxxxxxxxxxxxx</p>
 </div>
 <h2 id="bob">Strong leadership from start to finish</h2>
 <div>
  <p>fffffffffff</p>
 </div>
 <h2>Certainty of delivery, no matter how complex or difficult</h2>
 <div>
  <p>dddddddddd</p>
 </div>
</div>

在jQuery中,我有这个:

And in jQuery I have this:

$(".accordion").accordion({
 autoHeight: false,
 collapsible: true,
 navigation: true,
 active: 'none'
});

但是我仍然无法通过链接打开#bob面板.

But I still cant get the #bob panel to open via the link.

有什么想法吗?我把头发拔了.

Any ideas? Im pulling my hair out.

A.

推荐答案

您可以这样做:

$(".accordion").accordion({
 autoHeight: false,
 collapsible: true,
 navigation: true,
 active: 'none'
});
if(location.hash) $(location.hash).click();

这将在<h2>上执行click(通过使用哈希,其中包括#作为 #id选择器),调用标准的手风琴行为.

This would perform a click on the <h2> (by using the hash, which includes the # as an #id selector), invoking the standard accordion behavior.

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

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