我尝试使用这里提到的 cloneNode Copy the content of one table into another但是 Chrome 说 cloneNode 不是一个函数
https://jsfiddle.net/4wczdykc/1/
<table>
<thead>
<tr>
<th scope="col" colspan="1">TABLE TO CLONE</th>
</tr>
<tr>
<th>Column</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
脚本:
myTable = document.getElementsByTagName("Table")[0];
myClone = myTable.cloneNode(true);
document.body.appendChild(myClone);
最佳答案
getElementsByTagName()
方法访问具有指定标记名的所有元素。因此您必须选择 NodeList 的第一个元素。所以通过 [0] 来选择它。
myTable = document.getElementsByTagName("table")[0];
myClone = myTable.cloneNode(true);
document.body.appendChild(myClone);
关于javascript - 如何在 Javascript 中克隆整个表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35114530/