简体   繁体   English

如果使用引导程序,如何在单击按钮时将一个选项卡切换到另一个选项卡?

[英]How to switch one tab to another on button click if using bootstrap?

I have a page where i have 4 tabs. 我有一个页面,其中有4个标签。 I want to move first tabs if user click on button. 如果用户单击按钮,我想移动第一个标签。 Same button is showing on all tabs. 所有选项卡上都显示相同的按钮。 If user is on first tab, then user remains on first tab after clicking on button and if user is on any other tab except first tab then user should move to first tab on clicking button.I am using bootstrap.Here is my code: 如果用户位于第一个选项卡上,则用户在单击按钮后仍保留在第一个选项卡上,如果用户位于除第一个选项卡之外的其他任何选项卡上,则用户应单击按钮后移至第一个选项卡。我正在使用bootstrap。这是我的代码:

  <div class="tabsControlStyling">
        <ul class="nav nav-tabs">
                        <li class="active"><a data-toggle="tab" href="#home"> Home</a></li>
                        <li><a data-toggle="tab" href="#menu1">Menu1</a></li>
                        <li><a data-toggle="tab" href="#menu2">Menu2</a></li>
                        <li><a data-toggle="tab" href="#menu3"> Menu3</a></li>
                        @*<li><a data-toggle="tab" href="#menu3">Menu 3</a></li>*@
                    </ul>

          <div class="tab-content">
                <div id="home" class="tab-pane fade in active">
                //Content
                </div>
                <div id="menu1">
                </div>
                <div id="menu2">
                </div>
                <div id="menu3">
                </div>
          </div>
</div>

How i can switch to tab "home" on clicking button. 我如何在单击按钮时切换到选项卡“主页”。 I have tried this but it's not working. 我已经尝试过了,但是没有用。

$('#button').submit(function () {
                debugger;
                $("#home").tab('show');
});

This is not working. 这是行不通的。 How i can do this? 我该怎么做?

This should work for you, haven't tested it. 这应该为您工作,尚未测试。

$('#button').submit(function () {
    $("#tabsControlStyling").tabs({
        active: $("#home")
    });
});

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

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