2010-10-26 63 views
0

我有一个噩梦试图让这个工作(并已看过其他职位,但我仍然有问题)。jQuery手风琴 - 链接打开某些div

基本上我有一个像这样的链接:

/test.php#bob 

上test.php的我有这样的:

<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中我有这样的:

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

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

任何想法?我把我的头发拉出来。

A.

回答

2

你可以这样说:

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

这将执行上一<h2>click(通过使用散列,其中包括#作为#id selector),调用标准手风琴行为。