阻止html中onclick事件冒泡,处理方法上多加事件一个参数,不须要传值。javascript


<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <meta charset="utf-8" /> </head> <body> <div style='background:red;width:200px;height:50px' onclick='a()'> <input type='button' value='ok' onclick='b()'></input> </div> <script type="text/javascript"> function a(e){ alert("this div") } function b(e){ alert("this button") if(e&&e.stopPropagation){ e.stopPropagation(); }else{ window.event.cancelBubble =true; } } </script> </body> </html>
结果:阻止,button按钮上的click事件冒泡,前端事件以下,或者如图阻止事件冒泡html