[英]jQuery UI tabs: get current tab index
我想使用jQuery UI
选项卡获取当前选项卡的索引:特别是当show
或select
事件被触发时,我想知道这个选项卡是否可以参考?
You can use this to find 您可以使用它来查找
var $tabs = $('#tab').tabs();
var selected = $tabs.tabs('option', 'selected');
From JQuery 1.9 on 从JQuery 1.9开始
var $tabs = $('#tab').tabs();
var selected = $tabs.tabs('option', 'active');
$('#tabs').tabs({
select: function(event, ui) { // select event
$(ui.tab); // the tab selected
ui.index; // zero-based index
},
show: function(event, ui) { // show event
$(ui.tab); // the tab shown
ui.index; // zero-based index
}
});
Or, if you don't want to bind the event listeners on the initialization you can bind them like this: 或者,如果您不想在初始化时绑定事件侦听器,则可以像这样绑定它们:
$('#tabs')
.bind('tabsselect', function(event, ui) { // select event
$(ui.tab); // the tab selected
ui.index; // zero-based index
})
bind('tabsshow'. function(event, ui) { // show event
$(ui.tab); // the tab shown
ui.index; // zero-based index
});
I just implemented this in one of my projects: 我刚刚在我的一个项目中实现了这个:
var lastTab = 0; // global variable
$(function() {
$('#tabs').tabs({
select: function(event, ui) {
lastTab = ui.index;
}
});
});
And then anywhere else in your code you can simply reference lastTab
. 然后在代码中的任何其他位置,您只需引用
lastTab
。
For jQuery 1.9 or newer... 对于jQuery 1.9或更新版本...
$('#tabs').tabs({
activate: function(event, ui) {
ui.newTab.index(); // zero-based index
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.