解决事件冒泡
作者:互联网
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <style> #a{ width: 100px; height: 100px; background: red; border: 1px solid; } #box{ width: 200px; height: 200px; background: blue; border: 1px solid; } </style> </head> <body> <div id="box"> <div id='a'></div> </div> </body> </html> <script> document.getElementById("box").onclick=function(){ console.log("box"); } document.getElementById("a").onclick=function(even){ even.stopPropagation(); //将even(事件)作为参数,就是这个“点击”事件,通过这个even,可以获取到event.target.stopPropagation()解决事件冒泡
console.log("a"); }
</script>
标签:even,box,100px,height,冒泡,解决,border,stopPropagation,事件 来源: https://www.cnblogs.com/yjbyjb/p/11904668.html