如何将函数传递给jquery ui选项卡的活动选项?

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

如何将函数传递给jquery ui选项卡活动选项?

我可以将函数传递给jquery ui选项卡的激活选项,例如这样

activate: function(event, ui){
    localStorage.setItem("#" + $(this).context.id + "-current-index", $(this).tabs('option', 'active'));
}

如何使用活动选项获取这些值,下面的代码不起作用

active: function(event, ui){
    localStorage.getItem("#" + $(this).context.id + "-current-index")
}
jquery jquery-ui jquery-ui-tabs
1个回答
0
投票

您可能想要查看.getItem()。我建议以下内容:

function getData(i){
  return localStorage.getItem(i);
}

然后您可以像这样使用它:

active: function(event, ui){
  ui.newPanel.html(getData("#" + $(this).context.id + "-current-index"));
}

如果仍需要帮助,请提供Minimal, Reproducible Example

更新

activate(event,ui)类型:tabsactivate

激活选项卡后触发(动画完成后)。如果选项卡先前已折叠,则ui.oldTabui.oldPanel将是空的jQuery对象。如果选项卡正在折叠,则ui.newTabui.newPanel将是空的jQuery对象。

查看更多:https://api.jqueryui.com/tabs/#event-activate

ui.newPanel是表示“ 刚刚激活的面板。”的jQuery对象,因此我们可以在该对象上使用.html()

。html(htmlString)

描述:设置匹配元素集中每个元素的HTML内容。

查看更多:https://api.jquery.com/html/

© www.soinside.com 2019 - 2024. All rights reserved.