如何处理 jquery ui 选项卡小部件的选择事件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15931433/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:03:27  来源:igfitidea点击:

How to handle select event of tab widget of jquery ui?

jqueryjquery-uitabs

提问by GingerJim

I use tab widget of jquery ui in my webpage The initialization is ok. but want to capture the on_selected event of a tab to do something else. I followed docs of jquery but it does not work. doc!

我在我的网页中使用了 jquery ui 的选项卡小部件 初始化没问题。但想要捕获选项卡的 on_selected 事件以执行其他操作。我遵循了 jquery 的文档,但它不起作用。医生

I have tried

我试过了

    $( "#editor-tabs" ).tabs();
    $("#editor-tabs").bind("tabsshow",function(event,ui){
            alert(ui.index);
    });

and

$( "#editor-tabs" ).tabs({
    select: function(event,ui){alert(ui.index);}
});

Put breakpoints to the callback function and they are not hit.

将断点放在回调函数中,它们不会被命中。

回答by GingerJim

if you use jquery ui 1.10.* , following code is correct. I used the docby mistake. It is only for 1.8

如果您使用 jquery ui 1.10.* ,以下代码是正确的。我错误地使用了文档。仅适用于 1.8

Better to check your version number if you got a similar problem.

如果您遇到类似问题,最好检查您的版本号。

        $("#editor-tabs" ).tabs({                                                                  
            activate:function(event,ui){                                                       
                            alert(ui.index);                                                   
                    }                                                                          
         });   

回答by technopia

See my response for this question which is similar:

请参阅我对这个问题的回答,这是类似的:

https://stackoverflow.com/a/17509685/763629

https://stackoverflow.com/a/17509685/763629

Note for jQuery UI 1.10.x+ use this:

注意 jQuery UI 1.10.x+ 使用这个:

ui.newTab.index()

回答by DerStoffel

Would you mind posting a code example? According to http://api.jqueryui.com/tabs/therer is no "on_selected" event, but activate, beforeActivate, beforeLoad, create and load.

你介意发布一个代码示例吗?根据http://api.jqueryui.com/tabs/没有“on_selected”事件,而是激活、beforeActivate、beforeLoad、创建和加载。

Also what goal do you want to achieve?

还有你想达到什么目标?

Maybe refer to this one: jQuery - trapping tab select event

也许可以参考这个:jQuery - trapping tab select event

 $('#tabs, #fragment-1').tabs({
  select: function(event, ui){
    // Do stuff here
  }
});