jQuery 引导程序 3 选项卡中的单击事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19096513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:11:27  来源:igfitidea点击:

Click event in bootstrap 3 tabs

javascriptjqueryjavascript-eventsonclicktwitter-bootstrap-3

提问by Denis

I have the following HTML:

我有以下 HTML:

<div id="channels">
    <ul class="nav nav-tabs" id="ul-channels">
        <li class="channel" data-roomid="lobby"><a class="link-channel" href="#lobby" data-toggle="tab">lobby</a></li>
        <li class="channel active selected" data-roomid="test"><a class="link-channel" href="#test" data-toggle="tab">test</a></li>
    </ul>
</div>

I need an event that occurs when switching tabs. Like this:

我需要一个在切换选项卡时发生的事件。像这样:

$('.nav-tabs a').click(function (e) {
    alert("Q");
});

I tried a lot of options, but I had no success. I will appreciate any help.

我尝试了很多选择,但都没有成功。我将不胜感激任何帮助。

回答by Denis

The final my solution:

最后我的解决方案:

$(document).on( 'shown.bs.tab', 'a[data-toggle="tab"]', function (e) {
   console.log(e.target) // activated tab
})