[英]How can I add a tab in jquery-ui Tabs and then select it?
I understand how to add a jquery-ui tab, and I understand how to select a tab by index number, but how can I both add a tab and then select it? 我了解如何添加jquery-ui选项卡,并且了解如何通过索引号选择选项卡,但是如何同时添加选项卡然后选择它呢?
For example, in the following demo you can add a tab, but then you have to click on it for it to be displayed: 例如,在下面的演示中,您可以添加一个选项卡,但随后必须单击它才能显示它:
http://jqueryui.com/demos/tabs/#manipulation http://jqueryui.com/demos/tabs/#manipulation
I'm on jquery 1.4.2 and jquery-ui 1.8rc3. 我正在使用jquery 1.4.2和jquery-ui 1.8rc3。
The 'length' and 'selected' options has been deprecated and removed now, so to select the last tab (which is the one that has just been added) use 'length'和'selected'选项现已被弃用并删除,因此要选择最后一个选项卡(刚添加的选项卡),请使用
$('#tabs').tabs('option', 'active', -1);
This works because if you specify negative values, the tabs are counted from the end backwards starting at -1. 之所以起作用,是因为如果您指定负值,则选项卡从-1开始从末尾开始计数。
After you have added the tab like the example just use the select method . 在像示例一样添加选项卡之后,只需使用select方法 。 You will have to know the index of the tab you just added.
您将必须知道刚添加的选项卡的索引。 If you just added it to the end you can use the length method , if not then you already know the index of the tab because you defined it when you added it.
如果只是将其添加到末尾,则可以使用length方法 ,否则,您将已经知道选项卡的索引,因为您是在添加时定义的。
Also, you can use this: 另外,您可以使用以下命令:
var $tabs = $('#tabs').tabs({ add: function(event, ui) { $tabs.tabs('select', '#' + ui.panel.id); } });
Docs here: http://docs.jquery.com/UI/Tabs#...immediately_select_a_just_added_tab 此处的文档: http : //docs.jquery.com/UI/Tabs#...immediately_select_a_just_added_tab
However, I'm having a problem where this bit of code only works after the first one that I add... ie: doesn't work for the first one. 但是,我有一个问题,即这段代码仅在我添加的第一个代码之后才起作用...即:第一个代码不起作用。 Can't figure that out...
想不通...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.