我使用的Greasemonkey腳本,並更新使用下面的代碼表。我附上了桌子的圖像。但是當我點擊刪除時,rowIndex爲所有行返回-1。我不明白爲什麼它返回-1。的rowIndex是返回-1
table = document.getElementById('keys-table');
if (!table) return;
table.innerHTML = '';
// header
row = document.createElement('tr');
th = document.createElement('th');
th.innerHTML = "Group"; row.appendChild(th);
th = document.createElement('th');
th.innerHTML = "Key"; row.appendChild(th);
th = document.createElement('th');
th.innerHTML = " "; row.appendChild(th);
table.appendChild(row);
// keys
for (i = 0 ; i < keys.length ; i++) {
row = document.createElement('tr');
td = document.createElement('td');
td.innerHTML = keys[i][0];
row.appendChild(td);
td = document.createElement('td');
td.innerHTML = keys[i][1];
row.appendChild(td);
td = document.createElement('td');
button = document.createElement('input');
button.type = 'button';
button.value = 'Delete';
button.addEventListener("click", function(event) {
DeleteKey(event.target.parentNode.parentNode.rowIndex,event.target);
}, false);
td.appendChild(button);
row.appendChild(td);
table.appendChild(row);
}