我想防止选项卡切换,直到 Ajax 调用完成。有什么办法可以做到这一点?现在(默认情况下)当我单击另一个选项卡时,它会切换到该选项卡。我想阻止这种情况,直到 Ajax 调用成功/完成。仅供参考:我正在使用 Jquery Tabs-3 插件。请帮帮我。
3 回答
To answer your other comment (By saying "hold the control", I mean to say that when 'tabsselect' even is triggered, next event which is 'tabsshow' shouldn't be triggered until ajax request gets complete/succeed
), you can't do that directly.
However, you could cancel the tabsselect
, but store the index of the tab that the user tried to switch to in a variable. Then, when the AJAX request finishes, check whether the variable holds a tab index (in case the user didn't switch tabs), and, if it does, switch to that tab. Make sure to reset the variable in case you make another AJAX request later.
要回答您的评论,
$('#tabs > ul').bind('tabsselect', function(event, ui) {
if(inAjaxRequest)
return false;
//Do whatever you're already doing here
return true;
});
我假设您正在使用jQuery UI Tabs;如果不是,请链接到您正在使用的内容。
如果是,您可以在开始加载时通过调用禁用选项卡,并在完成加载后.tabs('disable', index)
通过调用再次启用它。.tabs('enable', index)
您还可以传递一个索引数组。