需要当前为 jQuery 选项卡选择的选项卡 ID [英] Need currently selected tab ID for jQuery tabs

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

问题描述

我知道我可以获取当前选定选项卡的索引,但我可以以某种方式获取 ID(如果这是由选项卡事件触发的,则与 ui.panel.id 等效.).但它不是)当前选定的选项卡?我不想使用索引,因为选项卡的顺序可能会改变.我不喜欢使用样式标记,因为这些标记可能会在未来的版本中发生变化.有没有办法做到这一点?如果没有,我能否以某种方式使用索引来访问它(甚至可以先访问面板对象)?还有其他想法吗?

I know I can get the index of the currently selected tab but can I somehow get to the ID (the equivalent of the ui.panel.id if this were triggered by an tab event...but it's not) of the currently selected tab? I'd prefer not to use the index because ordering of the tabs might change. I prefer not to use the style markups as those may change in future releases. Is there a method for this? If not, can I somehow use the index to access this (maybe even by accessing the panel object first)? Any other ideas?

推荐答案

您可以使用 :visible 伪选择器定位可见面板:

You can use the :visible pseudo-selector to target the visible panel:

$("#tabs .ui-tabs-panel:visible").attr("id");

值得注意的是,您可以从 activate 事件:

It's worth noting that you can retrieve the active tab from the activate event:

$("#tabs").tabs({
    activate: function (event, ui) {
        console.log(ui.newPanel[0].id);
    }
});

这篇关于需要当前为 jQuery 选项卡选择的选项卡 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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