2013-03-12 61 views
12

我将代码从jQuery UI 1.8升级到1.10。获取激活标签索引

在1.8以下,标签更改时触发的事件为select,我可以通过ui.index访问所选标签的索引。

在1.10下,标签更改时触发的事件为activate。但是,我无法在事件参数ui中找到任何内容,告诉我新激活的选项卡的索引。

我该如何发现该索引?

回答

22

你可以用下面的办法http://jsfiddle.net/9ChL5/1/

$("#tabs").tabs({ 
    activate: function (event, ui) { 

     console.log(ui.newTab.index()); 
    } 
}); 
+0

只是好奇,如果有jQuery开发UI网站的.index()或任何其他属性的文档可用。我看到ui对象有[this answer](http://stackoverflow.com/a/15367388/684617)中提到的newTab/oldTab/newPanel/oldPanel。但我并没有看到有关其他财产存在的更多细节,至少在该页面上。 – GoldDragonTSU 2014-12-04 16:51:53

+1

@GoldDragonTSU'ui.newTab'是一个普通的jQuery对象,'index()'是jQuery的[index()](https://api.jquery.com/index/)(用“Type:jQuery”表示) [激活事件文档](http://api.jqueryui.com/tabs/#event-activate))。 – 2015-04-23 20:59:42

0

UI对象是还在这里,但似乎直接持有oldTab,NEWTAB,oldPanel,newPanel的jQuery的对象,所以你不需要索引找到要使用的对象。

http://api.jqueryui.com/tabs/#event-activate

ui Type: Object 

- newTab 
Type: jQuery 
The tab that was just activated. 
- oldTab 
Type: jQuery 
The tab that was just deactivated. 
- newPanel 
Type: jQuery 
The panel that was just activated. 
- oldPanel 
Type: jQuery 
The panel that was just deactivated. 
+0

我确实需要索引,因为我将活动索引作为用户首选项保存在数据库中。 – 2013-03-12 23:53:29