Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

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

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.

(我知道之前已经问过这个具体问题,但是我没有在jQuery UI Tabs插件上使用bind()事件获得任何结果。)

I just need the index of the newly selected tab to perform an action when the tab is clicked.

(我只需要新选择的选项卡的index ,以便在单击选项卡时执行操作。)

bind() allows me to hook into the select event, but my usual method of getting the currently selected tab does not work.

(bind()允许我挂钩到select事件,但是我通常的获取当前选中选项卡的方法不起作用。)

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) {

});

When I use this code, the ui object comes back undefined .

(当我使用这段代码时,ui对象返回undefined 。)

From the documentation, this should be the object I'm using to hook into the newly selected index using ui.tab.

(从文档中,这应该是我用来使用ui.tab挂??钩到新选择的索引的对象。)

I have tried this on the initial tabs() call and also on its own.

(我已经在初始的tabs()调用上尝试了这个,也是自己的。)

Am I doing something wrong here?

(我在这里做错了吗?)

  ask by Mark Struzinski translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you need to get the tab index from outside the context of a tabs event, use this:

(如果需要从tabs事件的上下文之外获取选项卡索引,请使用以下命令:)

function getSelectedTabIndex() { 
    return $("#TabList").tabs('option', 'selected');
}

Update: From version 1.9 'selected' is changed to 'active'

(更新:从版本1.9'选中'更改为'有效')

$("#TabList").tabs('option', 'active')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...