cell1.innerHTML=demo;
cell2.innerHTML=(Here I want the delete button to appear);
}
可以改为:
cell1.innerHTML=demo;
var delBtn = document.createElement('input');
delBtn.setAttribute('type', 'button');
delBtn.setAttribute('value', 'Delete');
delBtn.addEventListener('click', nameOfYourDelBtnHandlerFunction, false);
cell2.appendChild(delBtn);
}
编辑:示例按钮按下处理程序函数
function onRowDeleteBtn()
{
var pressedButton = this; // must attach the handler with addEventListener, otherwise 'this' will not hold the required value
var parentCell = pressedButton.parentNode; // get reference to the cell that contains the button
var parentRow = parentCell.parentNode; // get ref to the row that holds the cell, that holds the button
var parentTbody = parentRow.parentNode; // get ref to the tbody that holds the row, that holds the cell, that holds the button
parentTbody.removeChild(parentRow); // nuke the row element
}