使用 jQuery UI 选项卡,如何在单击选项卡后运行代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4176005/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
With jQuery UI tabs, how can I run code after a click on a tab?
提问by ben
With jQuery UI tabs, you can use the select method to run code when a tab is clicked:
使用jQuery UI tabs,您可以使用 select 方法在单击选项卡时运行代码:
$( ".selector" ).tabs({
select: function(event, ui) { ... }
});
But the code is run before the just clicked tab has been loaded. I need to run code after new tab has been loaded. How can I do this? Thanks for reading.
但是代码在加载刚刚点击的选项卡之前运行。我需要在加载新选项卡后运行代码。我怎样才能做到这一点?谢谢阅读。
采纳答案by Cubed Eye
$( ".selector" ).tabs({
load: function(event, ui) { ... }
});
回答by Darren
API HAS CHANGED. This event is now "activate"/"tasbactivate"; see http://api.jqueryui.com/tabs/#event-activate
API 已更改。此事件现在是“激活”/“tasbactivate”;见http://api.jqueryui.com/tabs/#event-activate
----- OLDAnswer below -----------
-----旧答案如下 -----------
Based on the question it's the tabsshow (not the tabsload) event that is desired...event is triggered when a tab is shown.
基于这个问题,它是所需的 tabsshow(而不是 tabsload)事件......当显示选项卡时会触发事件。
Code examples: ( from http://jqueryui.com/demos/tabs/)
代码示例:(来自http://jqueryui.com/demos/tabs/)
Supply a callback function to handle the show event as an init option.
提供一个回调函数来处理 show 事件作为 init 选项。
$( ".selector" ).tabs({
show: function(event, ui) { ... }
});
Bind to the show event by type: tabsshow.
按类型绑定到 show 事件:tabsshow。
$( ".selector" ).bind( "tabsshow", function(event, ui) {
...
});
The event is useful if you want to set focus on control or similar.
如果您想将焦点设置在控制或类似上,该事件很有用。
回答by JasonWoof
looks like you could bind to tabsload or tabsshow:
看起来您可以绑定到 tabsload 或 tabsshow:
http://jqueryui.com/demos/tabs/#Events
http://jqueryui.com/demos/tabs/#Events
example
例子
$('#example').bind('tabsshow', function(event, ui) { ... });