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

查看:111
本文介绍了需要当前为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天全站免登陆