js阻止冒泡
<html> <title></title> <head> <meta charset="utf-8"> <style type="text/css"> .divone{100px;height:100px;background:black;position: relative;cursor: pointer} .divchild{position: absolute;margin:10px;50px;height:50px;background:white;cursor: pointer} </style> <script type="text/javascript"> functiondivone(){ //这里是divone事件的代码 console.log('divone事件'); stopPropagation(); } functiondivchild(){ //这里是divchild事件的代码 console.log('divchild事件'); stopPropagation(); } functionstopPropagation(e) { e = e ||window.event; if(e.stopPropagation) { //W3C阻止冒泡方法 e.stopPropagation(); } else{ e.cancelBubble = true; //IE阻止冒泡方法 } } </script> </head> <body> <div onclick="divone(this)"> <div onclick="divchild(this)"></div> </div> </body> </html>