简体   繁体   English

jQuery UI选项卡,重新排列选项卡后,选项卡选择不一致

[英]Jquery UI tabs ,the tab select is inconsistent after rearranging the tabs

I am using Jquery UI tabs for a wizard applictaion .After rearranging the tabs (part of the client requirement),the select index is inconsistent.We cannot allow jquery sortable on the tabs since only some tabs can be rearranged and the tabs do have a context menu too.So I am using insertAfter and insertBefore commands after it is rearranged successfully at server side. 我正在将Jquery UI选项卡用于向导应用程序。重新排列选项卡(客户端要求的一部分)后,选择索引不一致。我们不允许在选项卡上对jquery进行排序,因为只能重新排列某些选项卡并且选项卡确实具有上下文菜单也是如此。所以在服务器端成功重新排列之后,我正在使用insertAfter和insertBefore命令。 In the fiddle the tabs are rearranged after button click :- 在小提琴中,单击按钮后重新排列了选项卡:-

Jquery Tabs Fiddle jQuery标签小提琴

     $("#btn").click(function(){
     $("#tabs ul li:nth-child(3)").after($("#tabs ul li:nth-child(1)"));

 });

Refreshing the tabs after rearranging is not an option for us.Any help would be really appreciated 重新整理后刷新选项卡不是我们的选择。任何帮助将不胜感激

It seems to me the select event first, returns the active tab, and then changes which tab is active. 在我看来, select事件首先出现,返回活动选项卡,然后更改哪个选项卡处于活动状态。 You won't receive the correct value if that is the case. 在这种情况下,您将不会收到正确的值。 You should instead use the activate event: 您应该改用activate事件:

Javascript: 使用Javascript:

 $(function() {
     $("#btn").click(function(){
         $("#tabs ul li:nth-child(3)").after($("#tabs ul li:nth-child(1)"));
     });
  });

$( "#tabs" ).tabs({
    activate: function(event,ui){
         var selected = $(ui.newTab).index();
         alert(selected);
    }
});

Here is the fiddle 这是小提琴


EDIT: 编辑:

You can use index instead of active to find which tab is which based on it's position in the DOM. 您可以使用index而不是active来基于DOM中的位置查找哪个选项卡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM