【问题标题】:How to pass a function to active option of jquery ui tabs?如何将函数传递给jquery ui选项卡的活动选项?
【发布时间】:2020-05-10 11:21:16
【问题描述】:

如何将函数传递给 jquery ui tabs active 选项?

我可以像这样将一个函数传递给 jquery ui tabs activate 选项

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

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

active: function(event, ui){
    localStorage.getItem("#" + $(this).context.id + "-current-index")
}

【问题讨论】:

    标签: jquery jquery-ui jquery-ui-tabs


    【解决方案1】:

    您可能想查看.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/

    【讨论】:

    • 感谢@Twisty 付出的时间和精力,我需要对代码部分ui.newPanel.html 进行一点解释,它实际上是做什么的?
    • 谢谢@Twisty,你对我另一个问题的回答对我有用,这个答案没有。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    相关资源
    最近更新 更多