我创建了一个 addRow 函数,它允许我向表中添加行。添加行后,我想创建一个选项来删除新行。有没有办法回收我的功能?
function addRow() {
var table = document.getElementById('dataTable');
var rowCount = table.rows.length;
var newRow= table.insertRow((1));
var c0 = newRow.insertCell
c0.innerHTML="<div ><img src='include/images/cross.png' alt='delete row' onclick='deleteRow(rowCount)'/></div>";
}
function deleteRow(row){
var elem = document.getElementById('tr'+row);
var old = (elem.parentNode).removeChild(elem);
}