Bootstrap tabpanel 选择了哪个选项卡

hol*_*inn 3 javascript twitter-bootstrap

我正在使用这样的引导程序tabpanel:

<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>
Run Code Online (Sandbox Code Playgroud)

使用 javascript 我需要弄清楚用户在哪个选项卡上。我真的不知道如何做到这一点。我已经阅读了很多关于选择活动选项卡的内容,但我真的不知道如何检查用户选择了哪个选项卡。

更新:

我忘了提到我需要能够检查条件 if 语句选择了哪个选项卡,然后根据哪个选项卡处于活动状态执行某些操作。

我需要做这样的事情:

<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>
Run Code Online (Sandbox Code Playgroud)

She*_*med 9

检查这个

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

当他们点击一个标签时添加这个

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