需要当前为 jQuery 选项卡选择的选项卡 ID

编程入门 行业动态 更新时间:2024-10-28 02:31:28
本文介绍了需要当前为 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

本文发布于:2023-11-06 22:01:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564789.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选项卡   jQuery   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!