1 回答
TA贡献1811条经验 获得超6个赞
您可以parent通过parentNode 获取并删除itself。
<div onclick="this.parentNode.removeChild(this)"> @item </div>
function onDelete(elm, id) {
// Do something with id
console.log(id)
elm.parentNode.removeChild(elm)
}
<p><strong>Click to remove</strong></p>
<div onclick="this.parentNode.removeChild(this)">
1
</div>
<div onclick="this.parentNode.removeChild(this)">
2
</div>
<div onclick="this.parentNode.removeChild(this)">
3
</div>
<div onclick="this.parentNode.removeChild(this)">
4
</div>
<div>
<a href="#" onclick="this.parentNode.parentNode.removeChild(this.parentNode)"> href sample</a>
</div>
<div>
<a href="#" onclick="this.parentNode.parentNode.removeChild(this.parentNode)"> href sample 2</a>
</div>
<div onclick="onDelete(this, '1221')">
onDelete Function sample
</div>
- 1 回答
- 0 关注
- 69 浏览
添加回答
举报