代码之家  ›  专栏  ›  技术社区  ›  Renari

Jquery UI-重新加载所选选项卡?

  •  7
  • Renari  · 技术社区  · 14 年前

    5 回复  |  直到 14 年前
        1
  •  26
  •   Community CDub    8 年前

    更新:在jQuery1.9中 selected active attomman's answer.

    tabs('option','selected')

    例如,如果你有一个按钮 #button (以及 #tabs 元素被制成选项卡)在要获取索引的位置,请执行以下操作:

    $("#button").click(function() {
        var current_index = $("#tabs").tabs("option","selected");
    });
    

    下面是一个演示: http://jsfiddle.net/sVgAT/


    var current_index = $("#tabs").tabs("option","selected");
    $("#tabs").tabs('load',current_index);
    

    在jQuery1.9及更高版本中,您将执行以下操作:

    var current_index = $("#tabs").tabs("option","active");
    $("#tabs").tabs('load',current_index);
    
        2
  •  7
  •   attomman    12 年前

    http://jqueryui.com/upgrade-guide/1.9/#deprecated-selected-option-renamed-to-active

    现在使用“active”而不是“selected”

    所以代码看起来像:

    var current_index = $("#tabs").tabs("option","active"); $("#tabs").tabs('load',current_index);

        3
  •  2
  •   Bernd    12 年前

    如果其他人偶然发现了这个问题,并且像我一样正在使用jqueryeasyui的标签,那么Simen上面的回答就行不通了。相反,要刷新选项卡,请使用:

    var tab = $('#tt').tabs('getSelected');
    tab.panel('refresh');
    

    在哪里? tt id 通过创建的选项卡组的

    <div id="tt" class="easyui-tabs">
    
        4
  •  1
  •   Dave Robertson    12 年前

    我设法让这个工作,但它现在加载第一个标签两次时,它是不活跃的。如果有人对此有任何建议,我们将不胜感激。 console showing a cancelled request to the server

      constructor: (@element) ->
        @tabIndex = 0
        @tabs = @element.find('#tabs')
        @tabs.tabs
          spinner: "Loading.."
          cache: false
          ajaxOptions:
            cache: false
            error: ( xhr, status, index, anchor ) ->
              $( anchor.hash ).html "Couldn't load this tab. We'll try to fix this as soon as possible."
    
        #add custom load to make sure they always reload even the current tab when clicked
        @element.find('ul li a').click (e) =>
          if @tabIndex is @tabs.tabs('option', 'selected')
            @tabs.tabs 'load', @tabs.tabs('option', 'selected')
            @tabIndex = @tabs.tabs('option', 'selected')
    
        5
  •  0
  •   Wassim Sboui    10 年前

    下载此cookie插件:

    http://plugins.jquery.com/cookie/

    将jQuery cookie插入页面

     <script src="jquery.cookie.js"></script>
    

    $(".tabs").click(function() {
        //getter , get the active tab
        var active = $( "#tabs" ).tabs( "option", "active" );
        $.cookie("tabs_selected", active);
    });
    
    var cookieValue = $.cookie("tabs_selected");
    // setter, set the active tab stocked 
    $( "#tabs" ).tabs( "option", "active",cookieValue );