单击jQuery UI选项卡/使其处于活动状态时触发函数吗? [英] Trigger a function when a jQuery UI tab is clicked/made active?

查看:82
本文介绍了单击jQuery UI选项卡/使其处于活动状态时触发函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆