2010-11-01 217 views

回答

1

如果点击存在ui-tabs-selected类你可以检查。假设你使用的是标准的标记:

// in your click event 
var selected_exists = $('#yourTabBox') 
    .children('ul.ui-tabs-nav') 
    .children('li.ui-tabs-selected') 
    .length; 

if (selected_exists) { 
    // Nothing is collapsed 
} else { 
    // collapsed 
} 

这是完美的select事件。

+0

@Stephen ......他认为他可能会告诉我们他试过什么或什么? ';)'......当然会很高兴知道他在和谁打架呢? – jcolebrand 2010-11-01 20:31:06

+1

@drachenstern:同意。如果我们所描述的不起作用,我们需要查看一些已经尝试过的示例以及一些标记。 – Stephen 2010-11-01 20:33:37

+1

很好的答案(+1,如果我还有任何投票!)。注意在'select'事件中,'this'是外部div元素,所以你的代码可以简化为'$(this).children('ul.ui-tabs-nav> li.ui-tabs-selected “).length'。稍快,更灵活。 – lonesomeday 2010-11-01 20:38:51

1

show event怎么样?因为你不知道哪个隐藏了?

甚至可能是你想要的select event。使用'tabsselect'事件

$(".selector").tabs({ 
    collapsible: true, 
    select: function(event, ui) 
    { 
     var prevSelectedIndex = $(".selector").tabs('option', 'selected'); 
     var nextSelectedIndex = ui.index; 

     if(prevSelectedIndex === -1) 
     { 
      // It was previously collapsed and the user is now opening 
      // tab at index: nextSelectedIndex 
     } 
     else if(prevSelectedIndex === nextSelectedIndex) 
     { 
       // The user has clicked on the currently opened 
       // tab and it is collapsing 
     } 
    } 
}); 
+1

我遇到了这个问题,并用你的答案。我添加了一段代码来展示我如何使用它以备将来参考。 – 2012-08-03 02:22:27

相关问题