开发者

jQuery accordion - link to open certain 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 li开发者_运维知识库ke this:

/test.php#bob

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>

And in jQuery I have this:

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

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

Any ideas? Im pulling my hair out.

A.


You can do it like this:

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜