将元素插入两个Div

Muh*_*Ali 1 html javascript jquery

我正在创建表并将其填充为两个div,第一个div是小尺寸,第二个是大视图,其他图形工作正常但元素不工作,它填充最后一个div.你可以在这里看到代码和示例.

$("#sample").empty()
$("#fulls").empty()
var table = document.createElement('table');
table.className="report";
var first = table.insertRow(0);
first.className= "headerTable";
var h1 = first.insertCell(0);
var h2 = first.insertCell(1);
var h3 = first.insertCell(2);
var h4 = first.insertCell(3);
var h5 = first.insertCell(4);

h1.className= "headerTable";
h2.className= "headerTable";
h3.className= "headerTable";
h4.className= "headerTable";
h5.className= "headerTable";

h1.innerHTML = ("Speed");
h2.innerHTML = ("RPM");
h3.innerHTML =("Acc");
h4.innerHTML = ("Brake");
h5.innerHTML =("Dated");
for (var i = 0;i<5;i++)
{
    var first = table.insertRow((i+1));
    first.className= "tableRow";
    var h1 = first.insertCell(0);
    var h2 = first.insertCell(1);
    var h3 = first.insertCell(2);
    var h4 = first.insertCell(3);
    var h5 = first.insertCell(4);
    h1.innerHTML = i;
    h2.innerHTML = i;
    h3.innerHTML = i;
    h4.innerHTML = i;
    h5.innerHTML= new Date();
}
$("#fulls").html(table);
$("#sample").html(table);
Run Code Online (Sandbox Code Playgroud)

我尝试使用javascript但结果相同

document.getElementById("fulls").innerHTML = table;
document.getElementById("sample").innerHTML = table;
Run Code Online (Sandbox Code Playgroud)

Aru*_*hny 5

你不能在2个容器中插入一个元素,你需要克隆它

$("#fulls").html($(table).clone()); 
//or use cloneNode() like $("#fulls").html(table.cloneNode(true));
$("#sample").html(table);
Run Code Online (Sandbox Code Playgroud)

演示:小提琴

将相同的元素实例附加到2个容器时,它将从第一个容器中删除并添加到第二个容器中,因此如果要在两个位置保留副本,则需要克隆该元素.