javascript - 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
发生了什么?:(
解决方案
推荐阅读
- javascript - 是否保证在客户端智能支付按钮 .then() 之后会触发 webhook?
- mysql - MySQL 使用 leftjoin 和 select
- multicast - Wireshark 如何在不加入多播组的情况下捕获多播流量
- elasticsearch - 使用聚合结果过滤另一个索引中的文档
- jquery - 为什么导航汉堡图标不出现在手机上?
- arrays - Ruby on Rails - 模型
- javascript - Threejs中安装的钩子中的ReferenceError
- python - 在python中评估没有'*'符号的(几乎是代数)表达式
- mysql - 我可以使用 2 个主键(来自同一个表)作为其他表中的外键吗?
- python - 关于重新分配变量