简体   繁体   English

具有活动选项卡的动态Bootstrap导航

[英]Dynamic Bootstrap navigation with active tab

I have created my project on Bootstrap 3.3.6 now I am facing a problem with navigation whenever I clicked on any menu that will reset as it is, but I want to set it as active tab. 我现在在Bootstrap 3.3.6上创建了我的项目,每当我单击任何将按原样重置的菜单时,我都面临导航问题,但是我想将其设置为活动选项卡。 The Same problem happens with the sidebar. 侧栏发生相同的问题。 How can I resolve it ? 我该如何解决?

Thank You 谢谢

<ul class="sidebar-menu">
  <li class="header">HEADER</li>
  <!-- Optionally, you can add icons to the links -->
  <li class="active"><a href="index.php"><i class="fa fa-dashboard"></i> <span>Dashboard</span></a></li>
  <li class="treeview">
    <a href="#"><i class="fa fa-book"></i> <span>Admin</span> <i class="fa fa-angle-left pull-right"></i></a>
    <ul class="treeview-menu">
      <li><a href="setting.php"><i class="fa fa-circle-o"></i> Setting</a></li>
      <li><a href="adduser.php"><i class="fa fa-circle-o"></i> Add User</a></li>
      <li><a href="users.php"><i class="fa fa-circle-o"></i> Users</a></li>
    </ul>
  </li>
</ul>

You can make tab active by writing this line of code in click event of tab 您可以通过在选项卡的click事件中编写以下代码来使选项卡处于活动状态

$(this).addClass("active"); $(this).addClass(“ active”);

here You can find example 在这里你可以找到例子

http://www.bootply.com/70331# http://www.bootply.com/70331#

There are two ways. 有两种方法。

First (If your site is static) 首先(如果您的网站是静态的)

Just change the static class "active" on each page. 只需在每个页面上更改静态类“活动”即可。 If you have three menus- one, two , three then you will set class="active" on all three subsequent pages you open. 如果您具有三个菜单(一个,两个,三个),则将在随后打开的所有三个页面上设置class="active"
Say for one you have one.html for two you have two.html then you have to add the classes as per the menu page and remove the class from last page element. 假设一个有一个,那么one.html ,两个有一个, two.html那么您必须按照菜单页面添加类,并从最后一页元素中删除该类。

Second (Through jQuery) 第二(通过jQuery)

$(document).ready(function () {
  $("PreviousElementName").removeClass("active");//removes last manu item class
  $('CurrentElement').addClass('active'); // adds new menu item class
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM