我正在尝试链接到我的jQuery手风琴中的每个选项卡,但似乎无法正常工作...我对JavaScript不太好,所以想知道是否有人可以提供帮助。
标题中的代码...
<script>
$(document).ready(function() {
$("#accordion").accordion({collapsible: true, header: 'h3', navigation: true});
$(".accordion:first").show(); // <-- ADD IT HERE, AFTER THIS FIRST HIDE() CALL!
$("h3 a").click(function(event){
window.location.hash=this.hash;
});
});
</script>
在html中:
<li><a href="#global">Lorem ipsum</a></li>
应该打开以下选项卡:
<h3><a href="#global">Lorem ipsum</a></h3>
有什么想法...?
谢谢...
对于任何遇到相同问题的人,我都设法从头开始修复它,然后使用此操作:http://jsfiddle.net/tuando/ca8kv/1/
$("#accordion").accordion();
$(".section-link").click(function (e) {
e.preventDefault();
$("#accordion").accordion("activate", $(this).parent().index());
});
出色且轻巧的解决方案。
感谢任何研究的人。
- 您使用ID而不是类。
- 使用jQuery的attrapi获取HREF值
请尝试使用
$("#accordion:first").show()
$("h3 a").click(function(event){
window.location.hash=$(this).attr('href');
});
只需使用active
选项来定义哪个开始。
<script>
$(document).ready(function() {
$("#accordion").accordion({
active:0,
collapsible: true,
header: 'h3',
navigation: true
});
$("h3 a").click(function(event){
window.location.hash=this.hash;
});
});
</script>