2

I need to remove a child added with PHP. When I try to use removeChild, Chrome throws this:

Uncaught Error: NOT_FOUND_ERR: DOM Exception 8

Here is the code I am using to delete the element:

<!-- language: lang-js -->
document.getElementsByTagName('table')[0].removeChild(document.getElementById("e"+eid));

And here is the code that defines the element:

<!-- language: lang-html -->
<tr id='e0'>
   <td>
      gs
   </td>
   <td>
     <a href='#' onclick='showpm(0); return false;'>
       Open
     </a>
   </td>
   <td>
     <a href='#' onclick='delpm(7, 0); return false;'>
       Delete
     </a>
   </td>
</tr>
4

2 回答 2

4

Chrome 会tbody在您的表格中添加一个标签,因此您必须删除该元素的子元素,或者

var tr = document.getElementById("e"+eid);
tr.parentNode.removeChild(tr);
于 2012-09-03T18:13:00.037 回答
1

我认为您应该更好地使用表的 deleteRow() 方法,请参阅此处的示例

于 2012-09-03T18:11:23.853 回答