简体   繁体   中英

Select last generated tab by this function , jQuery Ui Tabs

I have this function to generate JQuery UI Tabs . I want to modify it as when the last tab is generated, set it as a opened tab, please help me .. I fully mixed up ... Thanks

function addTab(title,content,Refrence) {
            $("#tabs").show();
                        $("#tabs").tabs();
            var btnCloseTab = document.createElement('span');
            $(btnCloseTab).addClass('ui-icon ui-icon-close');
            $(btnCloseTab).attr('role', 'presentation');
            $(btnCloseTab).click(function () {
                $(this).parent().remove();
                var contentId = $(this).parent().find('a').attr('href');
                var contentIndex = contentId.substring(contentId.indexOf('-') + 1);
                for (var i = 0; i <= tabRefrenceArray.length; i++) {
                    if (Refrence == tabRefrenceArray[i]) {
                        tabRefrenceArray.splice(i, 1);
                    }
                    $(contentId).remove();
                }
            });
            var tabIndex = 1;
            if ($('#ulTab li:last').length > 0) {
                var liId = $('ul li a:last').attr('id');
                tabIndex = parseInt(liId.substring(2)) + 1;
            }
            var tabHeader = $('<li id="li-'+tabIndex+'" class="liTab"><a id="A-' + tabIndex + '" href="#tabs-' + tabIndex + '">' + title + '</a>');
            $(tabHeader).append(btnCloseTab);
            $(tabHeader).append('</li>');
            $("#ulTab").append(tabHeader);
            var tabContent = $('<div id="tabs-' + tabIndex + '">' + content + '</div>');
            $("#tabs").append(tabContent);
            $("#tabs").tabs("refresh");

        }

After the

$("#tabs").tabs("refresh");

do a

$("#tabs").tabs('option', 'active', -1); //  Activate the last one

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM