2

我正在研究 JQuery UI 选项卡。我想在提交表单后关闭动态生成的选项卡。

这是我的代码:

function submit_form(){
    alert(JSON.stringify($('form').serializeObject()));
    $('#result').text(JSON.stringify($('form').serializeObject()));
    var tabs = $("#container-1").tabs();
    tabs.tabs('remove', 1);
}

$(document).ready(function(){

    var tabs = $("#container-1").tabs();

    $('#add_tab').click( function(){

            var ul = tabs.find( "ul" );
            $( "<li><a href='#newtab'>New Tab</a></li>" ).appendTo( ul );
            $( "<div id='newtab'><form action='' method='post'>Name :<input type='text' name='name'></input></br>Email :<input type='text' name='email'></input></br>Phone Number :<input type='text' name='phone'></input></br><input type='button' value='Submit' id='form_button' onclick='submit_form()'></input></form></div>" ).appendTo( tabs );
            tabs.tabs( "refresh" );
            tabs.tabs( "option", "active", -1 );
    });
});

我的 HTML 页面:

<body>

<div id="container-1">
    <ul>
        <li><a href="#fragment-1">List</a></li>
    </ul>   
    <div id="fragment-1">
        <table id="contact">
        <tr>
        <th> Name </th>
        <th>E-mail </th>
        <th> Phone </th>
        </tr>
        </table>
    </div>
</div>

添加标签

我要关闭的选项卡是由函数动态创建的on-click of add_tab。我想在函数结束时关闭它submit_form()

它应该已与代码一起删除

tabs.tabs('remove', 1);

但我收到一个错误

Error: no such method 'remove' for tabs widget instance
http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js
Line 2

我该如何解决?

4

1 回答 1

7

The problem is that in the new jquery Ui the remove function has been deprecated use refresh method.

Old API:

$( "#tabs" ).tabs( "remove", 2 );

New API:

// Remove the tab
var tab = $( "#tabs" ).find( ".ui-tabs-nav li:eq(2)" ).remove();
// Refresh the tabs widget
$( "tabs" ).tabs( "refresh" );

Try fixing your issue with this in mind.

于 2013-01-30T08:45:54.500 回答