jQuery UI 标签 - 如何获取当前选择的标签索引 [英] jQuery UI Tabs - How to Get Currently Selected Tab Index

查看:50
本文介绍了jQuery UI 标签 - 如何获取当前选择的标签索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个具体问题已经之前问过,但我是使用 jQuery UI Tabs 插件上的 bind() 事件没有得到任何结果.

I know this specific question has been asked before, but I am not getting any results using the bind() event on the jQuery UI Tabs plugin.

我只需要新选择的选项卡的 index 即可在单击选项卡时执行操作.bind() 允许我挂入 select 事件,但是我通常的获取当前选定选项卡的方法不起作用.它返回先前选择的标签索引,而不是新的:

I just need the index of the newly selected tab to perform an action when the tab is clicked. bind() allows me to hook into the select event, but my usual method of getting the currently selected tab does not work. It returns the previously selected tab index, not the new one:

var selectedTab = $("#TabList").tabs().data("selected.tabs");

这是我试图用来获取当前选择的选项卡的代码:

Here is the code I am attempting to use to get the currently selected tab:

$("#TabList").bind("tabsselect", function(event, ui) {

});

当我使用这段代码时,ui 对象返回undefined.从文档中,这应该是我用来使用 ui.tab 连接到新选择的索引的对象.我已经在最初的 tabs() 调用中尝试过这个,也单独尝试过.我在这里做错了吗?

When I use this code, the ui object comes back undefined. From the documentation, this should be the object I'm using to hook into the newly selected index using ui.tab. I have tried this on the initial tabs() call and also on its own. Am I doing something wrong here?

推荐答案

对于 1.9 之前的 JQuery UI 版本:ui.index 来自 event 就是你想要的.

For JQuery UI versions before 1.9: ui.index from the event is what you want.

对于 JQuery UI 1.9 或更高版本:请参阅下面 Giorgio Luparia 的答案.

For JQuery UI 1.9 or later: see the answer by Giorgio Luparia, below.

这篇关于jQuery UI 标签 - 如何获取当前选择的标签索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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