从另一个页面链接到手风琴的一部分 [英] Linking to a section of an Accordion from another page
问题描述
我使用twitter-Bootstrap 2.04,并使用最新的jQuery。
我正在尝试制作一个链接,该链接将从一个页面转到包含此手风琴的页面,然后激活相应的手风琴部分。
这是手风琴:
I'm using twitter-Bootstrap 2.04, and I'm using the latest jQuery. I'm trying to make a link that will go from one page to the page containing this accordion, and then activate the appropriate accordion section. This is the accordion:
<div class="accordion-group">
<div class="accordion-heading">
<a name="Alink1" class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
<strong>Title</strong>
</a>
</div>
<div id="collapseOne" class="accordion-body in collapse" style="height: auto; ">
<div class="accordion-inner">
some random content
<div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a name="Alink2" class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
<strong>Title 2</strong>
</a>
</div>
<div id="collapseTwo" class="accordion-body collapse" style="height: 0px; ">
<div class="accordion-inner">
some random content 2
<div>
</div>
</div>
这是链接:
<a href="page.html/#Alink2">Link to some interesting stuff</a>
通过链接到页面中的某个部分,通常可以很好地工作,我是否需要使用Javascript来激活它?
With linking to just a bit in the page works fine usually, do I need to use Javascript to activate it?
推荐答案
是的,您需要在页面加载时手动激活它。类似下面的内容应该可以工作:
Yes, you will need to manually activate it on page load. Something like the following should work:
$(document).ready(function () {
location.hash && $(location.hash + '.collapse').collapse('show');
});
另外,正如@SaadImran所指出的,这里假设你链接到可折叠的元素id(例如。 , #collapseTwo
)而不是锚点中的名称(例如#Alink2
)。
Also, as @SaadImran pointed out, this assumes that you link to the collapsible element id (eg., #collapseTwo
) rather than the name in the anchor (eg., #Alink2
).
这篇关于从另一个页面链接到手风琴的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!