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

<!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>
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
  • 2021-12-17
  • 2022-12-23
猜你喜欢
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案