简体   繁体   English

如何将选项卡的内容克隆到其余选项卡

[英]How to clone the content of a tab to the rest of the tabs Jquery

I have a tab component from Jquery with severals tabs. 我从Jquery有几个选项卡的选项卡组件。 In principals all tabs have the same structure and components only the content in each component change. 原则上,所有选项卡都具有相同的结构和组件,仅每个组件中的内容都会更改。 I'm looking for a way how I can just copy or "clone" the components and structure of one tab in the rest. 我正在寻找一种方法来复制或“克隆”其余选项卡的组件和结构。 For example I have 5 tabs and all 5 will have the same structure like this 例如,我有5个标签,所有5个标签都将具有相同的结构

<div id="tabs">
  <ul id="tab">
    <li><a href="#tabs-1"></a></li>
    <li><a href="#tabs-2"></a></li>
    <li><a href="#tabs-3"></a></li>
    <li><a href="#tabs-4"></a></li>
    <li><a href="#tabs-5"></a></li> 
  </ul>

  <div id="tabs-1">
    <div class="row">
        <div class="col-xs-2">
            <label>Maschine:</label>
            <select id="slt-maschine" class="form-control">
                <option></option>
            </select>
        </div>
        <div class="col-xs-1">
            <label>Id:</label>
            <label id="id_maschine"></label>
        </div>
   </div>
 </div>
</div>

I don't want to copy and paste the same code for the rest of the tabs, I think is not the best solution and should exist a way to optimize this. 我不想为其余选项卡复制并粘贴相同的代码,我认为这不是最好的解决方案,应该存在一种优化方法。

var tabhtml= $('#tabs-1').html();
for(i=2;i<=5;i++){
  $('#tabs').append('<div id="tabs-'+i+'">'+tabhtml+'</div>');
}

U can try running this when document is ready. 您可以在准备好文档后尝试运行此文件。 One way to do it. 一种方法。

In this case don't use multiple DIVs for each tab. 在这种情况下,请勿为每个标签使用多个DIV。 Let the structure be one, perhaps use multiple tabs using ULs (as is in your code snippet). 让结构成为一体,或者使用UL使用多个选项卡(如代码段所示)。

Just reload the content using JavaScript while navigating between tabs. 在标签之间导航时,只需使用JavaScript重新加载内容即可。

-Nith -没有

Try: 尝试:

$('#tabs-x').html($('#tabs-1').html());

Be careful with your ID's. 请注意您的身份证。 In each tab you have the same ID's. 在每个选项卡中,您具有相同的ID。 (eg. id_maschine) (例如id_maschine)

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

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