首页 > 解决方案 > Javascript Html - 无法读取 null 的属性“删除”

问题描述

我有以下代码:

 var entry = document.createElement('li');
 entry.appendChild(document.createTextNode(nameChild));
 entry.setAttribute('id', idDoChild);

然后,我正在尝试这样做:

 cell1.innerHTML = "<img src='assets/trash' width='13px' height='13px' onclick='this.remove(); removeElement(" + idDoChild +")'>";


function removeElement (id){
    document.getElementById(id).remove();
}

但我有错误:

Cannot read property 'remove' of null

发生了什么?:(

标签: javascripthtml

解决方案


推荐阅读