var btnDelete=document.getElementById("del");
var boxs=document.getElementsByClassName("box");
//点击变为红色
for(var i=0;i<boxs.length;i++) {
boxs[i].onclick = function (e) {
e.stopPropagation && e.stopPropagation();
this.style.backgroundColor = "red";
};
}
//如果点击删除 就删除红色按钮
btnDelete.addEventListener("click",function(){
for(var i=0;i<boxs.length;i++){
if(boxs[i].style.backgroundColor =="red"){
boxs[i].parentNode.removeChild(boxs[i]);
}
}
});
添加回答
举报
0/150
提交
取消