var?btnDelete=document.getElementById("del");
var?boxs=document.getElementsByClassName("box");
//點(diǎn)擊變?yōu)榧t色
for(var?i=0;i<boxs.length;i++)?{
????boxs[i].onclick?=?function?(e)?{
????????e.stopPropagation?&&?e.stopPropagation();
????????this.style.backgroundColor?=?"red";
????};
}
//如果點(diǎn)擊刪除?就刪除紅色按鈕
btnDelete.addEventListener("click",function(){
????for(var?i=0;i<boxs.length;i++){
????????if(boxs[i].style.backgroundColor?=="red"){
????????????boxs[i].parentNode.removeChild(boxs[i]);
????????}
????}
});
這段話怎么可以簡(jiǎn)化一下
19990000
2017-10-03 21:29:37