点击"添加"按钮的时候如何将一段上面的代码添加到最后新一段?我写的是innerHTML,这种方法不支持输出document.getElementById("tableCondensed").getElementsByTagName("tr")[1],这个问题怎么解决?
#html
规格名字
规格明细
规格价格
库存数量
规格图片
操作方式
#javascript
function addSpecitem() {
var tableTh = document.getElementById("tableCondensed").getElementsByTagName("tr")[1];
var tableAddth = document.getElementById("tableCondensed");
tableAddth.innerHTML += tableTh;
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
确实,克隆一个……或者直接定义字符串(你要添加的tr所有的内容),往里面加。
document.querySelector('#tableCondensed tr').innerHTML添加按钮你应该放在,table外面。因为你这个添加不是针对这行进行的操作。
增加节点appendChild