我正在尝试使用以下函数来创建表行并将其删除 onclick 函数,以下是我尝试过的:
function CreateDelete()
{
var table = document.getElementById('newbook');
var tableBody = document.createElement('tbody');
var row, columnUserId, columnCountingAreaID, columnDeleteRec;
row = document.createElement('tr');
columnUserId = document.createElement('td');
columnUserId.appendChild(document.createTextNode("hi"));
columnCountingAreaID = document.createElement('td');
columnCountingAreaID.appendChild(document.createTextNode("there"));
columnDeleteRec = document.createElement('td');
var element = document.createElement("input");
//Assign different attributes to the element.
element.setAttribute('type','button');
element.setAttribute('name','X');
element.setAttribute('value','X');
element.onclick = function() {
$('#newbook input[type="button"]').click (function () {
$(this).closest('tr').remove();});
};
row.appendChild(columnUserId);
row.appendChild(columnCountingAreaID);
columnDeleteRec.appendChild(element);
row.appendChild(columnDeleteRec);
tableBody.appendChild(row);
table.appendChild(tableBody);
}
问题是它没有删除行 onclick 操作。任何人都可以告诉这里做错了什么。