jQuery UI选项卡 - 如何获取当前选定的选项卡索引 [英] jQuery UI Tabs - How to Get Currently Selected Tab Index

查看:197
本文介绍了jQuery UI选项卡 - 如何获取当前选定的选项卡索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个具体问题已经之前询问过,但我是使用 jQuery UI选项卡插件上的 bind()事件无法获得任何结果。

I know this specific question has been asked before, but I am not getting any results using the bind() event on the jQuery UI Tabs plugin.

我只需要新选择的选项卡的索引,即可在单击选项卡时执行操作。 bind()允许我挂钩到select事件,但是我通常的获取当前选中选项卡的方法不起作用。它返回先前选择的选项卡索引,而不是新选项卡索引:

I just need the index of the newly selected tab to perform an action when the tab is clicked. bind() allows me to hook into the select event, but my usual method of getting the currently selected tab does not work. It returns the previously selected tab index, not the new one:

var selectedTab = $("#TabList").tabs().data("selected.tabs");

以下是我试图用来获取当前所选标签的代码:

Here is the code I am attempting to use to get the currently selected tab:

$("#TabList").bind("tabsselect", function(event, ui) {

});

当我使用此代码时,ui对象返回 undefined 即可。从文档中,这应该是我用来使用ui.tab挂​​钩到新选择的索引的对象。我已经在最初的 tabs()调用中尝试了这个,也是自己的。我在这里做错了吗?

When I use this code, the ui object comes back undefined. From the documentation, this should be the object I'm using to hook into the newly selected index using ui.tab. I have tried this on the initial tabs() call and also on its own. Am I doing something wrong here?

推荐答案

对于1.9之前的JQuery UI版本:<$ c $来自事件的c> ui.index 就是你想要的。

For JQuery UI versions before 1.9: ui.index from the event is what you want.

对于JQuery UI 1.9或更高版本:请参阅下面的Giorgio Luparia的答案

For JQuery UI 1.9 or later: see the answer by Giorgio Luparia, below.

这篇关于jQuery UI选项卡 - 如何获取当前选定的选项卡索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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