سؤال

I have some logic which refreshes a portion of my page after I enter some data. The data entry form is on the second tab of a three tab table. When one tab is open the other two are closed.

When I enter the data, the refresh function closes the second tab and opens the first one again, I want the second tab to remain open.

I'm looking for a way of getting the index of the currently open tab which I think will put me on the right path to solving this problem.

So how do I get the index of the currently open tab?

Someone has already asked the same question but I can't seem to get the answer to work for me!

 var index;

 jQuery("#tabs").tabs({
     activate: function (event, ui) {
     index = (ui.newTab.index());
     }
 });
هل كانت مفيدة؟

المحلول

So after some more searching online and some trial and error, I found this works perfectly for me.

 var tab_idx;           

 function getSelectedTabIndex() { 
    return jQuery("#tabs").tabs('option', 'active');
 }

 tab_idx = getSelectedTabIndex();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top