jQuery UI tabs, select/unselect (collapse) events

我与影子孤独终老i 提交于 2019-12-24 16:04:08

问题


I am using jQuery UI 1.8.5 tabs plugin, with collapsible : true configuration. I need to call a function after a tab is collapsed to add a css class. Does anyone know how?


回答1:


You could check if the ui-tabs-selected class exists on click. Assuming you're using standard markup:

// 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
}

This is perfect for the select event.




回答2:


What about the show event won't work for this? Because you don't know which one was hidden?

Maybe even the select event might be what you want.

using the 'tabsselect' event:

$(".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
         }
    }
});


来源:https://stackoverflow.com/questions/4072745/jquery-ui-tabs-select-unselect-collapse-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!