单击jQuery UI选项卡/使其处于活动状态时触发函数吗? [英] Trigger a function when a jQuery UI tab is clicked/made active?
问题描述
我正在使用jQuery选项卡,并且其中一个选项卡中的内容是通过AJAX调用检索的.但是我不希望在单击选项卡(使其处于活动状态)之前触发呼叫,因为用户可能不一定会单击它.最好的方法是什么?
I'm using jQuery tabs and the content in one of the tabs is retrieved via an AJAX call. But I don't want to trigger the call until the tab is clicked (made active) because the user might not necessarily click it. What's the best way to do this?
jQuery的用户界面提供了
jQuery UI provides select
and show
events for the tabs, but these fire when any tab is selected or shown, not just a specific one (as far as I know).
我还尝试将click
事件分配给特定标签的ID:
I've also tried assigning a click
event to the specific tab's ID:
$("#my-tab").click(function(){
...
$.post(URL, function(data){
...
});
...
}
但这似乎没有任何作用,并且永远不会触发呼叫.
But this seemingly has no effect and the call is never triggered.
推荐答案
Ui标签提供了在选择标签时触发的功能.
Ui-tabs provide a function which is triggered when you select a tab.
$( ".yourTab" ).tabs({
select: function(event, ui) {
if(ui.index == myTabIndex) {
$.post(URL, function(data){
...
});
}
}
});
注意.对于新版本,请使用activate
.
Note Use activate
for new versions.
这篇关于单击jQuery UI选项卡/使其处于活动状态时触发函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!