[英]How to set active tab of jquery ui tabs using custom function?
I want to set active tab in jquery ui tabs based on output of a function active_tab(), but active_tab() function do not run when tabs are initialized.我想根据函数 active_tab() 的输出在 jquery ui 选项卡中设置活动选项卡,但是在初始化选项卡时不运行 active_tab() 函数。
function active_tab()
{
var t = 1;
// some conditions
return t;
}
$( "#tabs1" ).tabs({
active: function(){
active_tab();
}
});
jQuery UI Tabs option for active
expects a number, true
, or false
. active
jQuery UI Tabs 选项需要一个数字、 true
或false
。
Which panel is currently open.
当前打开的面板。 Multiple types supported:
支持多种类型:
- Boolean: Setting active to
false
will collapse all panels.布尔值:将 active 设置为
false
将折叠所有面板。 This requires the collapsible option to betrue
.这要求可折叠选项为
true
。- Integer: The zero-based index of the panel that is active (open).
整数:活动(打开)面板的从零开始的索引。 A negative value selects panels going backward from the last panel.
负值选择从最后一个面板向后的面板。
I would advise the following type of code:我会建议以下类型的代码:
function active_tab(tbs, i){
if(i == undefined){
i = 0;
}
// Add Other Conditions
tbs.tabs("option", "activate", i);
return i;
}
$("#tabs1").tabs();
activate_tabs($("#tabs1"), 1);
Another method would be:另一种方法是:
function active_tab(){
var t = 1;
// some conditions
return t;
}
$("#tabs1").tabs();
$("#tabs1").tabs("option", "activate", activate_tab());
You can also do the following:您还可以执行以下操作:
$("#tabs1").tabs({
activate: activate_tab()
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.