我以前使用jquery的选项卡扩展通过ajax加载页面片段,并隐藏或揭示页面中的隐藏div。这两种方法都有很好的文档,我没有问题。
然而,现在,我想做一些不同的选项卡。当用户选择一个选项卡时,它应该重新加载页面完全 – 这是因为每个选项卡部分的内容呈现一些昂贵的,所以我不想只是一次发送它们,并使用正常的方法切换“显示:无”来显示它们。
我的计划是拦截选项卡的“选择”事件,并通过操作document.location通过该功能重新加载页面。
如何在“选择”处理程序中,我可以获得新选择的选项卡索引和它对应的html LI对象吗?
$('#edit_tabs').tabs( {
selected: 2,// which tab to start on when page loads
select: function(e,ui) {
var t = $(e.target);
// alert("data is " + t.data('load.tabs')); // undef
// alert("data is " + ui.data('load.tabs')); // undef
// This gives a numeric index...
alert( "selected is " + t.data('selected.tabs') )
// ... but it's the index of the PREVIoUSLY selected tab,not the
// one the user is Now choosing.
return true;
// eventual goal is:
// ... document.location= extract-url-from(something); return false;
}
});
是否有可以读取的事件或ui对象的属性,它将给出新选择的选项卡或其中的锚标签的索引,ID或对象?
或者有更好的方法使用选项卡重新加载整个页面?
解决方法
我会看看
events的Tabs。以下取自jQuery文档:
$('.ui-tabs-nav').bind('tabsselect',function(event,ui) {
ui.options // options used to intialize this widget
ui.tab // anchor element of the selected (clicked) tab
ui.panel // element,that contains the contents of the selected (clicked) tab
ui.index // zero-based index of the selected (clicked) tab
});
看起来像ui.tab是要走的路。