我的html页面上有一些标签面板,每个标签都有一个href告诉标签,如下所示:
<li class="list"><a href="#tab6">FAQs / Ajuda</a></li>
但是我想从另一个页面打开#tab6并使我的活动标签上传。
有人可以给我一小段jquery样本来完成这个吗?
我想到了另一个页面调用的href:http://somelink.com/help.html#tab6
答案 0 :(得分:4)
试一试:
<li class="list"><a id="tab6" href="#tab6">FAQs / Ajuda</a></li>
$(function() {
var hash = window.location.hash || '#tab1';
// your code setting up your tabs
$(hash).click();
});
向与哈希值匹配的标签添加ID,并在之后添加$(hash).click();
,为您的标签设置.click()
处理程序。
答案 1 :(得分:4)
这是网址hash
。您可以获得类似的值,不需要jQuery:
var hash = window.location.hash;
答案 2 :(得分:0)
$(function(){
//use location.hash and do whatever you need to activate the tab here
});
答案 3 :(得分:0)
我不确定你究竟想做什么,但听起来你需要使用location.hash。
也许在页面加载时你可以调用类似
的东西if(location.hash == "#tab6"){
//put the code to set your tabs here
}