jquery ui tab select方法不起作用

时间:2013-07-05 15:44:41

标签: jquery-ui jquery jquery-ui-tabs

我有两个标签,每个标签上都有一个提交按钮。单击该按钮时,我需要重新加载该特定选项卡的内容以从服务器获取更新的数据。

if (validStatus()) {
    $.ajax({
        //...
        success: reloadTab
    });
}    

function reloadTab() {                
            var currentTab = $("#tabs").tabs("option", "active");
            alert(currentTab);
            $('#tabs').tabs('select', currentTab);
            alert(currentTab);
        }

单击该按钮时,选项卡不会刷新。我看到第一个警报但不是第二个。

HTML如下:

目:

    
<link rel="stylesheet" href="@this.Url.Content("//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css")" />
<script>
    $(function () {
        $("#tabs").tabs();
    });
</script>

体:

<div id="tabs">
<ul>
    <li><a href="#Tab1" title="Tab1">The first tab</a></li>
    <li><a href="#Tab2" title="Tab2">the second tab</a></li>
    <li><a href="#Success" title="Success">Success</a></li>
</ul>

<div id="Success">
    testing
</div>

<div id="Tab1">

    <fieldset >
        <legend>Overview</legend>
        <input type="button" id="submit1" value="submit" />
        <br />
    </fieldset>

    <fieldset style="width: 700px;">
        <legend>Overview</legend>
        <div>
            <table >
            //updated with ajax
            </table>
        </div>
    </fieldset>

    <script>
        //reloadTab is in here
    </script>
</div>

<div id="Tab2">

    <fieldset style="float:left; width:300px;">
        <input id="submit2" type="button" value="submit"/>
    </fieldset>

    <fieldset style="float:left;">
        <legend>Overview</legend>
        <table>
        //updated with ajax
        </table>
    </fieldset>

    <script>.....</script>
</div>

2 个答案:

答案 0 :(得分:5)

结果显示tabs.('select', ...)已被弃用,使用tabs.('option', 'active', index)解决了我的问题。此评论中的解决方案:https://stackoverflow.com/a/16033969/1463649

答案 1 :(得分:0)

您在浏览器的控制台中看到了什么吗?你在用什么浏览器?
试试这个来帮助你进行调试。

function reloadTab() {    

console.log($('#tabs')); // if this is an empty object, the element doesn't exist when you call this function
console.log($('#tabs').tabs()); // if this doesn't return 'function', you haven't included a library properly, maybe jquery ui, or jquery, or you're using an old version or something
console.log(currentTab); // if this is undefined then something went wrong and no tab is active            
        var currentTab = $("#tabs").tabs("option", "active");
        alert(currentTab);
        $('#tabs').tabs('select', currentTab);
        alert(currentTab);
    }