<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> #out{ width: 500px; height: 500px; background: red; position: relative; } #in{ width: 200px; height: 200px; background: green; position: absolute; } </style></head><body> <div id="out"> <div id="in"></div> </div> <script type="text/javascript"> var out = document.getElementById("out"); var i = document.getElementById("in"); out.addEventListener('click',a,true); i.addEventListener('click',b,false); function a(){ out.style.backgroundColor = 'black'; } function b(){ i.style.backgroundColor = 'blue'; } </script></body></html>在這段代碼中為何點擊子元素后父元素也會變色呢?在子元素上已經設置了阻止事件捕獲???
關于js中的事件問題
POPMUISE
2018-10-27 18:15:16