Twitter Bootstrap Tabs: Go to Specific Tab on Page Reload or Hyperlink(Twitter Bootstrap 选项卡:在页面重新加载或超链接时转到特定选项卡)
问题描述
我正在开发一个网页,其中我使用 Twitter 的 Bootstrap 框架及其 引导标签 JS.除了一些小问题外,它工作得很好,其中一个是我不知道如何从外部链接直接转到特定选项卡.例如:
I'm developing a web page in which I'm using Twitter's Bootstrap Framework and their Bootstrap Tabs JS. It works great except for a few minor issues, one of which is I do not know how go directly to a specific tab from an external link. For example:
<a href="facility.php#home">Home</a>
<a href="facility.php#notes">Notes</a>
当点击来自外部页面的链接时,应该分别转到主页选项卡和备注选项卡
should go to the Home tab and the Notes tab respectively when clicked on the links from an external page
推荐答案
这是我的解决方案,可能有点晚了.但它也许可以帮助其他人:
Here is my solution to the problem, a bit late perhaps. But it could maybe help others:
// 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;
})
这篇关于Twitter Bootstrap 选项卡:在页面重新加载或超链接时转到特定选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Twitter Bootstrap 选项卡:在页面重新加载或超链接时


基础教程推荐
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01