how to add and remove jquery tabs dynamically?

后端 未结 4 1851
广开言路
广开言路 2021-02-07 12:36

I have an aspx page on which I have 2 static jquery tabs.Upon clicking on a button avaiable on one of these tabs,I would like to add a new tab dynamically,which gets its content

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-07 12:54

    Have you tried using the add method of the tabs?

    var tabs = $("#tabs").tabs();
    $('#tabs-1 button').click(function(){
        tabs.tabs('add','/url_for_tab/','New tab');
    });
    

    Update -- As of jQuery UI 1.9 the add remove methods have been deprecated and in jQuery UI 1.10 they have been removed.

    The correct way to do this for remote (ajax) content tabs now is:

    var tabs = $( "#tabs" ).tabs();
    var ul = tabs.find( "ul" );
    $( "
  • New Tab
  • " ).appendTo( ul ); tabs.tabs( "refresh" );

    And for when you already have the content:

    var tabs = $( "#tabs" ).tabs();
    var ul = tabs.find( "ul" );
    $( "
  • New Tab
  • " ).appendTo( ul ); $( "

    New Content

    " ).appendTo( tabs ); tabs.tabs( "refresh" );

提交回复
热议问题