【问题标题】:jquery tabs - change tab after ajax calljquery 选项卡 - ajax 调用后更改选项卡
【发布时间】:2014-09-03 04:46:47
【问题描述】:

我使用 jquery-ui 选项卡组件。这是我页面中的代码

<ul>
    <li><a href="#tabs-1">Anagrafica</a></li>
    <li><a href="#tabs-2">Corsi</a></li>
    <li><a href="#tabs-3">Pagamenti</a></li>
</ul>
<div id="tabs-1">
    //
</div>  
<div id="tabs-2">
    //
</div>
<div id="tabs-3">
    //
</div>

组件完美运行

有没有办法在 ajax 调用后更改显示的选项卡?

当我执行 ajax 调用时,会显示 tab2。我想在 ajax 调用后显示 tab3

【问题讨论】:

    标签: jquery ajax jquery-ui-tabs


    【解决方案1】:

    在没有 jQueryUI 的情况下试试这些选项卡

    $('ul').each(function(){
        var $active, $content, $links = $(this).find('a');
    
        //Set focus when the page is reloaded
        $active = $($links.filter('[href="'+location.hash+'"]')[0] || $links[0]);
        $active.parent().addClass('active');
        $content = $($active.attr('href'));
    
        //Hide containers
        $links.not($active).each(function () {
            $($(this).attr('href')).hide();
        });
    
        //Set click event
        $(this).on('click', 'a', function(e){
            $active.parent().removeClass('active');
            $content.hide();
            $active = $(this);
            $content = $($(this).attr('href'));
            $active.parent().addClass('active');
            $content.show();
            e.preventDefault();
        });
    });
    

    【讨论】:

      【解决方案2】:

      是的,只需使用active 选项:

      $("ul").tabs("option", "active", 1); // Select tab 2
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-08
        • 1970-01-01
        • 2013-03-10
        • 1970-01-01
        相关资源
        最近更新 更多