We are working on a Bootstrap website to present our schoolwork. I have a fair understanding of the used html code, but I am having one problem.
To link to a specific tab/section within a page this link is used:
href="#tab"
I have copied the original index.html and thus created a second webpage. I'm able to link to this page using:
href="page2.html"
But I'm not able to link directly to a tab/section on that second page. I tried using href="page2.html/#tab"
or "page2.html#tab"
etc. But it doesn't work yet, I think I miss some fundamental knowledge about this coding.
Could anyone explain me how to get this working, in 'normal' language. There are several (older) solutions, but can't get them to work in the javascript files.
答案 0 :(得分:0)
这应该有帮助...
http://codepen.io/mattsince87/pen/exByn
LINK - &gt; <a id="link1" class="nav-section1" href="#section1">S1. Info</a>
内容 - &gt; <h1 id="section1">1. Info</h1>
答案 1 :(得分:0)
你可以使用这样的东西,因为我在项目中运行了这个东西。这些将检查页面是否包含选项卡,然后它将从page2的url获取最后一个值并使其可见。
if($("#tabs").length)
{
var id = window.location.hash.substr(1);
$('#tabs a[href="#'+id+'"]').tab('show');
}