Javascript 单击按钮时更改活动的引导程序选项卡
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32339617/
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
Change the active bootstrap tab on button click
提问by Farjad Hasan
I want to change the active bootstrap tab on the click of another button.
我想通过单击另一个按钮来更改活动的引导程序选项卡。
I have tried add id's to the tabs li and write custom jquery code.
我尝试将 id 添加到选项卡 li 并编写自定义 jquery 代码。
$('#emailNotify').click(function () {
$('#notify').addClass('active').attr('aria-expanded','true');
$('#myacc').removeClass('active').attr('aria-expanded','false');
});
This code works fine on first click but it doesn't change back when I tried to click My Account tab again.
此代码在第一次单击时可以正常工作,但是当我再次尝试单击“我的帐户”选项卡时它不会变回来。
Markup:
标记:
<ul class="content-list museo_sans500">
<li><a href="javascript:void(0)">Change Password</a></li>
<li><a id="emailNotify" data-toggle="tab">Change Email Notifications</a></li>
<li><a href="javascript:void(0)">Change Profile Picture</a></li>
</ul>
回答by Carlos Mayo
You can change the active tab on the click event button with that:
您可以使用以下内容更改单击事件按钮上的活动选项卡:
$('#changetabbutton').click(function(e){
e.preventDefault();
$('#mytabs a[href="#second"]').tab('show');
})
Here's a JSFiddle with an example:
这是一个带有示例的 JSFiddle:
回答by bigOther
You should use twitter-boostrap wayto change between tabs:
您应该使用twitter-boostrap 方式在选项卡之间切换:
$('#myTab a:first').tab('show'); // Select first tab
$('#myTab a:last').tab('show'); // Select last tab
or
或者
$('#notify').tab('show'); // show notification tab