如何使用自定义功能设置jquery ui选项卡的活动选项卡?

问题描述 投票:0回答:1

我想基于功能active_tab()的输出在jquery ui选项卡中设置活动选项卡,但是在初始化选项卡时,active_tab()函数不会运行。

function active_tab()
{
    var t = 1;
    // some conditions
    return t;
}

$( "#tabs1" ).tabs({
    active: function(){
        active_tab();
    }
});
jquery-ui jquery-ui-tabs
1个回答
0
投票

active的[jQuery UI Tabs选项需要一个数字,truefalse

哪个面板当前处于打开状态。支持多种类型:

  • 布尔值:将活动设置为false将折叠所有面板。这要求可折叠选项为true
  • 整数:活动(打开)的面板的从零开始的索引。负值选择从最后一个面板开始倒退的面板。

我建议使用以下类型的代码:

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);

另一种方法是:

function active_tab(){
  var t = 1;
  // some conditions
  return t;
}

$("#tabs1").tabs();
$("#tabs1").tabs("option", "activate", activate_tab());

您还可以执行以下操作:

$("#tabs1").tabs({
  activate: activate_tab()
});
© www.soinside.com 2019 - 2024. All rights reserved.