html - 从另一个页面定位 bootstrap 4 选项卡面板

标签 html css twitter-bootstrap bootstrap-4

当我单击索引页面上的链接时,我想在 service.html 页面上打开一个选项卡面板。我正在使用 bootstrap nav-pills,这是我已经尝试过但没有用的部分内容。

服务.html

<div class="nav flex-column nav-pills col-md-3" id="v-pills-tab" role="tablist" aria-orientation="vertical">
<li class="nav-item">
    <a class="nav-link list-group-item" id="v-pills-manpower-tab" data-toggle="pill" href="#v-pills-manpower" role="tab" aria-controls="v-pills-manpower" aria-selected="false">Manpower Support</a>
</li>
</div>

<div class="tab-content col-md-8" id="v-pills-tabContent">
<div class="tab-pane fade" id="v-pills-manpower" role="tabpanel" aria-labelledby="v-pills-manpower-tab">
    <h5>Manpower Support</h5>
</div>
</div>

这是我的 index.html 文件中的链接

<a href="services.html#v-pills-manpower">Manpower</a>

目前,这只会将我带到默认服务页面,但不会打开我想要的选项卡内容。实现它的正确方法是什么?

最佳答案

在你的service.html中添加以下代码

$(function(){
  var tabPanelId = window.location.hash.substr(1).trim();
  // tabPanelId will give your "v-pills-manpower" id
  $("#"+tabPanelId").click();
});

关于html - 从另一个页面定位 bootstrap 4 选项卡面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48200480/

相关文章:

css - :first-child with *ngFor is not working properly

javascript - 用于突出显示文本的 JQuery 选择器

javascript - 我有一个用户可以自动下载 pdf 文件的网站,它不应该在新标签页中打开

jquery - BootStrap 多个事件导航选项卡问题

javascript - 带有 Bootstrap 模式和 AJAX 的 Intro.js

javascript - Bootstrap 社交按钮

javascript - 使用背景图像作为页面结构?

css - 如何为 Zend 表单设置 css?

html - 对齐同一行内的图像

html - 调整/放大/缩小页面时,div 会四处移动