<html> <title></title> <head> <Meta charset="utf-8"> <style type="text/css"> .divone{width:100px;height:100px;background:black;position: relative;cursor: pointer} .divchild{position: absolute;margin:10px;width:50px;height:50px;background:white;cursor: pointer} </style> <script type="text/javascript"> function divone(){ //这里是divone事件的代码 console.log('divone事件'); } function divchild(){ //这里是divchild事件的代码 console.log('divchild事件'); stopPropagation(); } function stopPropagation(e) { e = e || window.event; if(e.stopPropagation) { //W3C阻止冒泡方法 e.stopPropagation(); } else { e.cancelBubble = true; //IE阻止冒泡方法 } } </script> </head> <body> <div class="divone" onclick="divone(this)"> <div class="divchild" onclick="divchild(this)"></div> </div> </body> </html>
转载于:https://www.cnblogs.com/gasolhome/p/12375571.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。