.tabs用法ajax,jQuery UI Tabs: How to switch to a (ajax) tab with

当禁用缓存时,可以通过设置每个标签的'cache.tabs'数据来控制其缓存行为。首次加载标签内容后,可以启用该标签的缓存。可以通过在$(document).ready中设置当前选中标签的缓存状态。另外,可以使用beforeLoad回调函数检查标签是否已加载,如果已加载则阻止重新加载,并设置ajax请求不缓存。还可以通过监听标签选择事件,当选择标签但不加载内容。
摘要由CSDN通过智能技术生成

可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):

问题:

When the caching remains disabled (i.e. cache: false), how can I prevent the tab from loading the remote content again? Essentially, I would like to select a tab but not load it.

回答1:

It turns out that you can control the caching of each tab by setting the 'cache.tabs' data in each tab's anchor element.

I posted the answer in another post: JQuery UI Tabs caching, but I'll just repost the code here.

// disable cache by default

$("#tabs").tabs({

cache: false,

});

Then after the tab content has been loaded for the first time, you can enable the caching for that tab. I simply put it in the $(document).ready for the page to be cached:

$(document).ready(function () {

// cache content for the current tab

var currentTabIndex = $("#tabs").tabs('option', 'selected');

var currentTabAnchor = $("#tabs").data('tabs').anchors[currentTabIndex];

$(currentTabAnchor).data('cache.tabs', true)

});

回答2:

$(function () {

$("#tabs").tabs({

beforeLoad: function (event, ui) {

if (ui.tab.data("loaded")) {

event.preventDefault();

return;

}

ui.ajaxSettings.cache = false,

ui.panel.html('loader.gif Loading...'),

ui.jqXHR.success(function() {

ui.tab.data( "loaded", true );

}),

ui.jqXHR.error(function () {

ui.panel.html(

"Couldn't load Data. Plz Reload Page or Try Again Later.");

});

}

});

});

回答3:

...follow a tab's URL instead of loading its content via ajax

Note that opening a tab in a new window is unexpected, e.g. inconsistent behaviour exposing a usablity problem (http://www.useit.com/alertbox/tabs.html).

$('#example').tabs({

select: function(event, ui) {

var url = $.data(ui.tab, 'load.tabs');

if( url ) {

location.href = url;

return false;

}

return true;

}

});

By: http://jqueryui.com/demos/tabs/#...immediately_select_a_just_added_tab

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值