简体   繁体   English

如何将jquery-ui选项卡克隆到其他位置

[英]How to clone jquery-ui tabs to different loc

I tried to clone tabs element to different location by using clone(true) method but it didn't work properly. 我尝试通过使用clone(true)方法将tabs元素克隆到其他位置,但是无法正常工作。 For example, I can not switch between tabs in '#here' div. 例如,我不能在'#here'div中的选项卡之间切换。

Here is the html content: 这是html内容:

<body>

<div id="tab1" class="tabs" style="height:100px; width:300px">
    <ul></ul>
</div>

<div id="here" style="height:100px; width:300px"></div>
</body>

and this is the code which I tried: 这是我尝试的代码:

$('#tab1').tabs({ closable: true });

$('#tab1').tabs('add', '#' + 1, 'test');
$('#tab1').tabs('add', '#' + 2, 'test');


var tmp = $('#tab1').clone(true);

tmp.appendTo($('#here'));

I don't want to copy html tags and then reinitialize the tabs element like this: 我不想复制html标记,然后像这样重新初始化tabs元素:

$('#tab1').tabs({ closable: true });

$('#tab1').tabs('add', '#' + 1, 'test');
$('#tab1').tabs('add', '#' + 2, 'test');


$('#here').html($('#tab1').html());
$('#here').tabs();

I actually want to relocate tabs, which has ui elements like jqgrid, jstree in it, to different div dynamically and the above code is not appropriate solution. 我实际上想将具有ui元素(如jqgrid,jstree)的选项卡动态地重新定位到不同的div,并且上述代码不是合适的解决方案。

thanks for your attention. 感谢您的关注。

If you want to reallocate i think you could use detach() so that you can reappend the elements later 如果您想重新分配,我想您可以使用detach()以便以后可以重新添加元素

var tab = $('#tab1').detach();
tab.appendTo($('#here'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM