jQuery选项卡 – 获取以前选择的选项卡的索引

jQuery 1.7.1 – 我想获得以前选择的选项卡的索引。 例如:如果我从1st移动到第3个选项卡,我想将之前选择的选项卡索引设为0.如何实现此目的?

我试过这个 ,但那没用。

我有以下标记,

 

JAVASCRIPT,

 $('#tabs').tabs( { select: function(e, ui) { var t = $(e.target); alert( "Index " + t.data('selected.tabs') ); return true; }}); 

当select或show回调触发时,您只能使用ui.index获取当前选择的标记。 您最好的选择是跟踪该索引并在选项卡切换时更新它,这将在更新之前告诉您之前的索引。

 var previousIndex = 0; $('#tabs').tabs( { select: function(e, ui) { //do whatever you need to do with previousIndex alert("The previously selected tab index was " + previousIndex); //track the new index previousIndex = ui.index; } }); 

你可以在select:选项中使用$(this).tabs('option', 'selected')

喜欢

 $("#tabs").tabs({ select: function(event, ui){ console.log($(this).tabs('option', 'selected')} )} });