首页 > 代码库 > 阻止事件冒泡
阻止事件冒泡
<!doctype html> <html> <head> <title></title> <meta charset = "utf-8"/> </head> <style type="text/css"> #grandpa{width:300px;height:300px;background:green;} #father{width:200px;height:200px;background:gray;} #self{width:100px;height:100px;background:pink;} </style> <script type="text/javascript"> function self(evt){ alert("我被打击了") if(event&&event.stopPropagation){//非IE event.stopPropagation(); }else{//IE window.event.cancelBubble=true; } } function father(){ alert("爸爸被打击了") } function grandpa(){ alert("爷爷被打击了") } </script> <body> <div id="grandpa" onclick="grandpa()"> <div id="father" onclick="father()"> <div id="self" onclick="self()"> 我是最内层的哦; </div> </div> </div> </body> </html>
阻止事件冒泡
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。