用于活动选项卡更改的 Bootstrap 3 jquery 事件 [英] Bootstrap 3 jquery event for active tab change

查看:20
本文介绍了用于活动选项卡更改的 Bootstrap 3 jquery 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当引导程序 3 选项卡/导航栏的选项卡更改时,我花了不切实际的时间来尝试触发一个函数,并且实际上所有 google 吐出的建议都是错误的/不起作用.

如何解决这个问题?

元见评论

解决方案

$('a[data-toggle="tab"]').on('shown.bs.tab', function (e){var target = $(e.target).attr("href")//激活的标签警报(目标);});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script><link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/><ul id="myTab" class="nav nav-tabs"><li class="active"><a href="#home" data-toggle="tab">Home</a></li><li class=""><a href="#profile" data-toggle="tab">Profile</a></li><div id="myTabContent" class="tab-content"><div class="tab-pane淡入淡出"id="home">首页标签!

<div class="tab-pane淡入淡出" id="profile">个人资料标签!

I spent an unrealistic amount of time trying to fire a function when the tab changes of the bootstrap 3 tab/navbar and literally all suggestions google spat out were wrong/did not work.

How to go about this?

Meta-edit: see comment

解决方案

$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  var target = $(e.target).attr("href") // activated tab
  alert(target);
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>

<ul id="myTab" class="nav nav-tabs">
  <li class="active"><a href="#home" data-toggle="tab">Home</a></li>
  <li class=""><a href="#profile" data-toggle="tab">Profile</a></li>
</ul>
<div id="myTabContent" class="tab-content">
  <div class="tab-pane fade active in" id="home">
    home tab!
  </div>
  <div class="tab-pane fade" id="profile">
    profile tab!
  </div>
</div>

这篇关于用于活动选项卡更改的 Bootstrap 3 jquery 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆