Bootstrap选项卡在另一页上打开选项卡

我有一个页面上有自举标签,它们链接到该页面上的正确内容区域。

当你离开那个页面时,我在顶部有相同的标签,我想引导他们回到上一页,右边的标签打开。

这是我的标签在外部页面上的样子

 

正如您所看到的,我已尝试链接到该页面并调出id,该ID将转到右侧页面,但不会打开该选项卡。

我也试过在jquery中搞乱它,但没有足够的有效显示。 任何帮助将非常感激!

编辑:

另一页上的标签看起来像这样。 只是基本的bootstrap tabbing。

  

我最后再做了一些工作,并提出了这个选择正确的选项卡并打开正确的内容面板

  //grabs the hash tag from the url var hash = window.location.hash; //checks whether or not the hash tag is set if (hash != "") { //removes all active classes from tabs $('#tabs li').each(function() { $(this).removeClass('active'); }); $('#my-tab-content div').each(function() { $(this).removeClass('active'); }); //this will add the active class on the hashtagged value var link = ""; $('#tabs li').each(function() { link = $(this).find('a').attr('href'); if (link == hash) { $(this).addClass('active'); } }); $('#my-tab-content div').each(function() { link = $(this).attr('id'); if ('#'+link == hash) { $(this).addClass('active'); } }); } 

谢谢willbeeler的良好开端! 🙂

通过利用tab(’show’)可以大大简化这一过程。

 $(document).ready(function() { var hash = window.location.hash; if (hash != "") $('#tabs a[href="' + hash + '"]').tab('show'); else $('#tabs a:first').tab('show'); }); 

我认为这也会奏效。 我测试它,它适合我:)

 $(document).ready(function() { var hash = window.location.hash; hash && $('ul.nav a[href="' + hash + '"]').tab('show'); }); 

好的,我测试了它,它对我有用。 在调用jQuery之后,在某处添加以下代码。 这应该在page.php(外部页面链接到的主页面)上。 如果这有帮助,请告诉我。

 $( document ).ready(function() { //grabs the hash tag from the url var hash = window.location.hash; //checks whether or not the hash tag is set if (hash != "") { //removes all active classes from tabs $('#tabs li').each(function() { $(this).removeClass('active'); }); //this will add the active class on the hashtagged value var link = ""; $('#tabs li').each(function() { link = $(this).find('a').attr('href'); if (link == hash) { $(this).addClass('active'); } }); } }); 

编辑:顺便说一句,我需要给下面的堆栈溢出问题提供一些道具: 获取URL哈希位置,并在jQuery中使用它在那里我得到第一行找到哈希变量。

一个适合我的小修改:

  

标签部分:

  

标签内容部分:

 

用于外部链接的url:

 Account 

在我的案例中,Url看起来像:

  Account