zoukankan      html  css  js  c++  java
  • 取消html中onclick的事件冒泡

       阻止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;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

    结果:阻止,button按钮上的click事件冒泡,前端事件如下,或者如图阻止事件冒泡

  • 相关阅读:
    SQL 代码片段
    SQL
    Python List
    python_enumerate用法
    HashMap记录
    Brute Force(暴力算法)
    python解析html文件,提取标签中一个元素
    每五分钟统计一次数据
    grep
    expect
  • 原文地址:https://www.cnblogs.com/licorice/p/10171713.html
Copyright © 2011-2022 走看看