<body>
<div class="sss" id="board">
<button>点击生成节点</button>
</div>
<script>
var board = document.getElementById("board");
document.getElementsByTagName("button")[0].onclick=function () {
var e = document.createElement("input");
e.type = "button";
e.value = "子节点";
board.appendChild(e);
remove_del()
};
function remove_del() {
let im=document.getElementsByTagName("input");
for (let i=0;i<im.length;i++){
im[i].onclick=function () {//每个创造节点添加事件
board.removeChild(im[i]);//删除节点
remove_del()
}
}
}
</script>
</body>
网友评论