jQuery UI Tabs - how can I disable top menu?

家住魔仙堡 提交于 2019-12-10 22:52:54

问题


I'm trying to disable top menu on jQuery UI Tabs - so the tabs would be operated with next/prev buttons only.

Disable option form the doc does not seams to work as expected.

Please see my example here: Live Demo

jQuery code:

    $(document).ready( function() {

  $(function() {

            var $tabs = $('#tabs').tabs();

            $(".ui-tabs-panel").each(function(i){

              var totalSize = $(".ui-tabs-panel").size() - 1;

              if (i != totalSize) {
                  next = i + 2;
                     $(this).append("<a href='#' class='next-tab mover' rel='" + next + "'>Next Page &#187;</a>");
              }

              if (i != 0) {
                  prev = i;
                     $(this).append("<a href='#' class='prev-tab mover' rel='" + prev + "'>&#171; Prev Page</a>");
              }

            });

            $('.next-tab, .prev-tab').click(function() { 
                   $tabs.tabs('select', $(this).attr("rel"));
                   return false;
               });


        });

});

Any ideas how can I disable top menu, but keep the structure, style etc.. ?


回答1:


How about just enable the tab to be selected just before selecting it, and then disable the tabs again?

So, at the initialisation, all tabs are disabled:

    var $tabs = $('#tabs').tabs({
        disabled: [0, 1, 2]
    });

And when selecting the tab, enable it before selecting it, and then disable all tabs again:

        $tabs.tabs('enable', tabIndex)
            .tabs('select', tabIndex)
            .tabs("option","disabled", [0, 1, 2]);

See it in action: http://jsfiddle.net/william/y6QeV/21/.


EDIT: You can simply disable just the old tab:

        var newTabIndex = $(this).attr("rel");
        var oldTabIndex = $tabs.tabs('option', 'selected');
        $tabs.tabs('enable', newTabIndex)
            .tabs('select', newTabIndex)
            .tabs('disable', oldTabIndex);

Example: http://jsfiddle.net/william/y6QeV/22/.



来源:https://stackoverflow.com/questions/7979063/jquery-ui-tabs-how-can-i-disable-top-menu

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