且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在后台预加载JQuery UI选项卡

更新时间:2023-11-04 11:18:46

尝试如下操作:

$tabs = $('#tabs').tabs({
    cache: true
});
var total = $tabs.find('.ui-tabs-nav li').length;
var currentLoadingTab = 1;
$tabs.bind('tabsload',function(){
    currentLoadingTab++;
    if (currentLoadingTab < total)
        $tabs.tabs('load',currentLoadingTab);
    else
        $tabs.unbind('tabsload');
}).tabs('load',currentLoadingTab);

它使用cache选项初始化选项卡,以便在一次加载后不会重新加载选项卡. 然后,它找出选项卡的总数,并将要加载的下一个选项卡设置为1(以0开头的选项卡进行索引) 然后,它将一个事件绑定到加载事件上,以开始加载下一个选项卡,直到将所有选项卡都击中.要启动它,然后加载第二个选项卡.

It initializes the tabs with the cache option so that tabs aren't reloaded after they have been loaded once. It then finds out the total number of tabs and sets the next tab to load as 1 (tabs are indexed starting with 0 ) Then it binds an event on the load event to start loading the next tab until it has hit all of them. To start it of it then loads the second tab.