<!DOCTYPE?html>
<html?lang="en">
<head>
????<meta?charset="UTF-8">
????<title>Title</title>
????<style>
????????div{
????????????width:80px;
????????????height:80px;
????????????border:1px?solid?#000;
????????}
????</style>
</head>
<body>
<div?class="aaa"?id="p1">
????<span>111</span>
????<div?class="aaa"?id="p2">
????????<span>2222</span>
????????<div?class="aaa"?id="p3">
????????????<span>333</span>
????????</div>
????</div>
</div>
<script>
var?divs=document.getElementsByClassName("aaa");
for(var?i=0;i<divs.length;i++){
????divs[i].onclick=function(e){
????????this.parentNode.removeChild(this);
????}
}
</script>
</body>
</html>
當(dāng)我點(diǎn)擊P3的時候,會全部刪除?是不是觸發(fā)了 冒泡 怎么才能阻止呢?
19990000
2017-10-03 10:03:35