[英]Bootstrap tabpanel which tab is selected
我正在使用这样的引导程序选项卡:
<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>
使用 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>
使用jQuery获取活动选项卡的ID,因为它内置在Bootstrap中:
id = $(".active").attr('tab-pane id');
然后,只需执行以下操作:
$('#' + id)
检查这个
var id = $('.tab-content .active').attr('id');
if(id == "delayedspiff") {
alert("delayedspiff");
}
else {
alert("instantspiff");
}
当他们单击选项卡时,添加此
$('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.