gpt4 book ai didi

javascript - Twitter Bootstrap 选项卡 : Go to Specific Tab on Page Reload or Hyperlink

转载 作者:bug小助手 更新时间:2023-10-28 10:55:14 25 4
gpt4 key购买 nike

我正在开发一个网页,我在其中使用 Twitter 的 Bootstrap 框架和他们的 Bootstrap Tabs JS .除了一些小问题外,它工作得很好,其中一个是我不知道如何从外部链接直接转到特定选项卡。例如:

<a href="facility.php#home">Home</a>
<a href="facility.php#notes">Notes</a>

当点击来自外部页面的链接时,应该分别转到主页选项卡和备注选项卡

最佳答案

这是我对问题的解决方案,可能有点晚了。但它也许可以帮助其他人:

// Javascript to enable link to tab
var hash = location.hash.replace(/^#/, ''); // ^ means starting, meaning only match the first hash
if (hash) {
$('.nav-tabs a[href="#' + hash + '"]').tab('show');
}

// Change hash for page-reload
$('.nav-tabs a').on('shown.bs.tab', function (e) {
window.location.hash = e.target.hash;
})

关于javascript - Twitter Bootstrap 选项卡 : Go to Specific Tab on Page Reload or Hyperlink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7862233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com