[英]Bootstrap Nav Tabs - Fire Javascript
I'm using a basic Bootstrap tab structure, where I wish to fire a Javascript event once the tab is clicked. 我使用的是基本的Bootstrap标签结构,我希望在其中单击该标签后触发Javascript事件。 I can't figure out how to do this.
我不知道该怎么做。 This is the code I have come up with so far:
到目前为止,这是我想出的代码:
<ul class="nav nav-tabs nav-justified">
<li class="active"><a data-toggle="tab" href="#tab1"> tab(<?php echo $count ?>) </a></li>
<li><a data-toggle="tab" href="#menu2"> tab(<?php echo $count3 ?>) </a></li>
<li><a data-toggle="tab" href="#menu1"> tab(<?php echo $count2 ?>) </a></li>
</ul>
and the Javascript: 和Javascript:
$("#menu2").click(function() {
alert('yes, the click actually happened');
});
$('.nav-tabs a[href="#menu2"]').click(function() {
You have to do: 你必须做:
$('[href=#menu2]').on('shown.bs.tab', function (e) {
alert('Your Code')
});
This event fires on tab show after a tab has been shown. 显示标签后,此事件会在标签显示上触发。 Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively.
使用event.target和event.relatedTarget分别定位活动选项卡和上一个活动选项卡(如果有)。
http://getbootstrap.com/javascript/ http://getbootstrap.com/javascript/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.