Need currently selected tab ID for jQuery tabs

2019-01-19 10:44发布

I know I can get the index of the currently selected tab but can I somehow get to the ID (the equivalent of the ui.panel.id if this were triggered by an tab event...but it's not) of the currently selected tab? I'd prefer not to use the index because ordering of the tabs might change. I prefer not to use the style markups as those may change in future releases. Is there a method for this? If not, can I somehow use the index to access this (maybe even by accessing the panel object first)? Any other ideas?

10条回答
我命由我不由天
2楼-- · 2019-01-19 11:04

After JQuery 1.9 selected is deprecated

So use

var active = $( "#jtabs" ).tabs( "option", "active" );

查看更多
倾城 Initia
3楼-- · 2019-01-19 11:06

For jQuery UI >= 1.9 you can use ui.newPanel.selector:

$('#tabs').on('tabactivate', function(event, ui) {
  console.log(ui.newPanel.selector);
});
查看更多
Rolldiameter
4楼-- · 2019-01-19 11:08

If you want the id (or actually the href) from the selected tab, you can use eq() to retrieve the jQuery Object.

You can see an example here: http://jsfiddle.net/svierkant/hpU3T/1/

查看更多
劳资没心,怎么记你
5楼-- · 2019-01-19 11:17
$("#tabs .ui-state-active a").attr("id");
查看更多
乱世女痞
6楼-- · 2019-01-19 11:21

For jquery version below 1.9:

 <div class="roundedFloatmenu">
        <ul id="unid">
            <li class="titleHover" id="li_search">Search</li>               
            <li class="titleHover" id="li_notes">Notes</li>
             <li class="titleHover active" id="li_writeback">Writeback</li>         
            <li class="titleHover" id="li_attorney">Attorney</li>
        </ul>
    </div 

And you can find the active tab using:

 jQuery('#unid').find('li.active').attr('id')
查看更多
Luminary・发光体
7楼-- · 2019-01-19 11:21

This works:

$('#divName .ui-tabs-panel[aria-hidden="false"]').prop('id');
查看更多
登录 后发表回答