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

编程入门 行业动态 更新时间:2024-10-28 04:23:01
本文介绍了需要当前为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:02:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564790.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选项卡   jQuery   ID

发布评论

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

>www.elefans.com

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