简体   繁体   English

Bootstrap tabpanel 选择了哪个选项卡

[英]Bootstrap tabpanel which tab is selected

I am using a bootstrap tabpanel like this:我正在使用这样的引导程序选项卡:

<div class="row spiff_tabs_body">
            <!-- Nav tabs -->
            <ul class="nav nav-tabs spiff_tabs" role="tablist">
                <li role="presentation" class="active">
                    <a href="#home" aria-controls="home" role="tab" data-toggle="tab" onclick="FormGet('dashboard/delayedspiff', 'delayedspiff')">Potential Spiff</a>
                </li>
                <li role="presentation">
                    <a href="#profile" aria-controls="profile" role="tab" data-toggle="tab" onclick="FormGet('dashboard/instantspiff', 'delayedspiff')">Instant Spiff</a>
                </li>
            </ul>
            <!-- Tab panes -->
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active" id="delayedspiff"></div>
                <div role="tabpanel" class="tab-pane" id="instantspiff"></div>
            </div>
        </div>
    </div>
</div>

Using javascript I need to figure out which tab the user is on.使用 javascript 我需要弄清楚用户在哪个选项卡上。 I'm not really sure how to do this.我真的不知道如何做到这一点。 I've read a lot about selecting the active tab, but I can't really find out how to check which tab the user has selected.我已经阅读了很多关于选择活动选项卡的内容,但我真的不知道如何检查用户选择了哪个选项卡。

Updated:更新:

I forgot to mention I need to be able to check in a conditional if statement which tab is selected and then do something based on which tab is active.我忘了提到我需要能够检查条件 if 语句选择了哪个选项卡,然后根据哪个选项卡处于活动状态执行某些操作。

I need to do something like this:我需要做这样的事情:

<script>
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
    // here is the new selected tab id
    var selectedTabId = e.target.id;
});

var id = $('.tab-content .active').attr('id');
if (id == "instantspiff") {
    alert("instantspiff");
}
else {
    alert("delayedspiff");
}
</script>

Get the id of the tab that is active, using jQuery because it is built into Bootstrap: 使用jQuery获取活动选项卡的ID,因为它内置在Bootstrap中:

id = $(".active").attr('tab-pane id');

And then, just do your stuff on: 然后,只需执行以下操作:

  $('#' + id)

check this 检查这个

var id = $('.tab-content .active').attr('id');
if(id == "delayedspiff") {
    alert("delayedspiff");
}
else {
    alert("instantspiff");
}

when they click on a tab add this 当他们单击选项卡时,添加此

$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
    // here is the new selected tab id
    var selectedTabId = e.target.id;
});

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

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