【问题标题】:Get Index of Activated Tab获取激活标签的索引
【发布时间】:2013-03-12 16:49:03
【问题描述】:

我正在将代码从 jQuery UI 1.8 升级到 1.10。

1.8以下,tab改变时触发的事件是select,我可以通过ui.index访问被选中的tab的索引。

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

我怎样才能发现那个索引?

【问题讨论】:

    标签: jquery-ui jquery-ui-tabs


    【解决方案1】:

    您可以使用以下方法http://jsfiddle.net/9ChL5/1/

    $("#tabs").tabs({
        activate: function (event, ui) {
    
            console.log(ui.newTab.index());
        }
    });
    

    【讨论】:

    • 很好奇 JQuery UI 站点上是否有 .index() 或任何其他可用属性的文档。我看到 ui 对象有 this answer 中提到的 newTab/oldTab/newPanel/oldPanel。但我没有看到关于其他属性存在的更多细节,至少在那个页面上。
    • @GoldDragonTSU ui.newTab 是这里的常规 jQuery 对象,index() 是 jQuery 的 index()(在 activate event docs 中用“Type: jQuery”表示)。
    【解决方案2】:

    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.
    

    【讨论】:

    • 我确实需要索引,因为我将活动索引作为用户首选项保存在数据库中。
    猜你喜欢
    • 2013-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多