1

I am trying to figure out an error with JQuery when I tried to create tabs for my ASP.Net application(I am a novice in JQuery)..

Below is the code I am trying, when I tried debugging using Chorme Dev.tool found error"no such method 'add' for tabs widget instance" and I found out "tabsDiv.tabs("add", '#main', pages[i][0]);" this does not work anymore as the "add" method is deprecated from the newer version of JQuery. Could anyone help me to find way to overcome this??

<script type="text/javascript">

    $(document).ready(function () {

        var pages = [
            ['Events', "/Listings.aspx", "/AddEvent.aspx", "UpdateOrDelete.aspx"],
            ['Performance', "/Performance.aspx"]
        ];

        var myPage = '<%=Request.Path %>';

        var tabsDiv = $('#masterTabsDiv');

    tabsDiv.tabs({
        select: function (event, ui) {
            document.location = pages[ui.index][1];
            return false;
        }
    });
    var indexToSelect = 0;

    for (var i = 0; i < pages.length; i++) {
        for (j = 0; j < pages[i].length; j++) {
            if (pages[i][j] == myPage) {
                indexToSelect = i;
                window.alert("set block 2");
                break;
            }
        }
        tabsDiv.tabs("add", '#main', pages[i][0]);
    }
    window.alert("set block 4");
    tabsDiv.find('li').removeClass('ui-tabs-selected ui-state-active');
    tabsDiv.find('li').eq(indexToSelect).addClass('ui-tabs-selected ui-state-active');
});
</script>

Thanks, Raam

4

1 回答 1

4

从 jQuery UI 1.10 开始,您需要向liDOM 添加一个新元素,然后调用.tabs("refresh"),因此您的代码将类似于

var tabsDiv = ('#masterTabsDiv');
tabsDiv.find('ul').append("<li><a href='#newTab'>New Tab</a></li>");
tabsDiv.append("<div id='newTab'>New content</div>");
tabsDiv.tabs("refresh");
于 2013-08-06T09:28:31.257 回答