jQuery UI 选项卡.如何根据其 id 而不是基于索引来选择选项卡 [英] jQuery UI tabs. How to select a tab based on its id not based on index

查看:17
本文介绍了jQuery UI 选项卡.如何根据其 id 而不是基于索引来选择选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个选项卡并配置了usign jQuery UI.

I have two tabs and configured usign jQuery UI.

ul  class="tabs"
  li  tabone
  li tabtwo
ul

动态地从后面的 C# 代码中隐藏或选择一些选项卡,比如说 tabtwo另一个选项卡必须隐藏或不显示.我可以使用 .tabs({selected:1});.tabs(disable:0). 在 JavaScript 中执行此操作,但我不想使用选项卡这样做的索引.

dynamically from C# code behind I will hide or select some tab let say tabtwo and the other tab has to be hidden or not shown. I can do this in JavaScript using .tabs({selected:1}); and .tabs(disable:0). but I don't want to use the tab indexes to do so.

是否有任何替代方法可以根据名称/ID 选择选项卡?

Is there any alternate to select tabs based on their name/id?

推荐答案

注意:由于对 jQuery 1.9 和 jQuery UI 的更改,此答案不再正确.请参阅下面@stankovski 的回答.

您需要首先找到选项卡的索引(这只是它在列表中的位置),然后使用 jQuery UI 提供的选择事件专门选择选项卡(选项卡->选择).

You need to find the tab's index first (which is just its position in a list) and then specifically select the tab using jQuery UI's provided select event (tabs->select).

var index = $('#tabs ul').index($('#tabId'));
$('#tabs ul').tabs('select', index);

更新:顺便说一句 - 我确实意识到这(最终)仍然是按索引选择的.但是,它不需要您知道选项卡的具体位置(特别是当它们按照问题中的要求动态生成时).

Update: BTW - I do realize that this is (ultimately) still selecting by index. But, it doesn't require that you know the specific position of the tabs (particularly when they are dynamically generated as asked in the question).

这篇关于jQuery UI 选项卡.如何根据其 id 而不是基于索引来选择选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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