简体   繁体   English

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

[英]How to pass a function to active option of jquery ui tabs?

How to pass a function to jquery ui tabs active option?如何将函数传递给 jquery ui 选项卡活动选项?

I can pass a function to jquery ui tabs activate option like this我可以像这样将一个函数传递给 jquery ui tabs activate 选项

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

How to get these value using active option, below code is not working如何使用活动选项获取这些值,下面的代码不起作用

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

You may want to review the .getItem() .您可能需要查看.getItem() I would suggest the following:我建议如下:

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

Then you can use it like so:然后你可以像这样使用它:

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

Update更新

activate( event, ui ) Type: tabsactivate激活(事件,用户界面)类型:tabsactivate

Triggered after a tab has been activated (after animation completes).在选项卡被激活后触发(动画完成后)。 If the tabs were previously collapsed, ui.oldTab and ui.oldPanel will be empty jQuery objects.如果选项卡先前已折叠, ui.oldTabui.oldPanel将是空的 jQuery 对象。 If the tabs are collapsing, ui.newTab and ui.newPanel will be empty jQuery objects.如果选项卡正在折叠, ui.newTabui.newPanel将是空的 jQuery 对象。

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

ui.newPanel is the jQuery Object that represents " the panel that was just activated. " So we can then use .html() on that object. ui.newPanel是代表“刚刚激活的面板”的 jQuery 对象。因此我们可以在该对象上使用.html()

.html( htmlString ) .html( html字符串 )

Description: Set the HTML contents of each element in the set of matched elements.说明:设置匹配元素集中每个元素的 HTML 内容。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM