jQuery accordion - link to open certain div

别说谁变了你拦得住时间么 提交于 2019-12-25 01:44:59

问题


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

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.


回答1:


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.



来源:https://stackoverflow.com/questions/4022775/jquery-accordion-link-to-open-certain-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!