zoukankan      html  css  js  c++  java
  • 阻止事件冒泡

    转自http://www.runoob.com/try/try.php?filename=tryjquery_event_stoppropagation

    <!DOCTYPE html>
    <html>
    <head>
    <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
    </script>
    <script>
    $(document).ready(function(){
    $("span").click(function(event){
    event.stopPropagation();
    alert("The span element was clicked.");
    });
    $("p").click(function(event){
    alert("The p element was clicked.");
    });
    $("div").click(function(){
    alert("The div element was clicked.");
    });
    });
    </script>
    </head>
    <body>

    <div style="height:100px;500px;padding:10px;border:1px solid blue;background-color:lightblue;">
    This is a div element.
    <p style="background-color:pink">This is a p element, in the div element. <br><span style="background-color:orange">This is a span element in the p and the div element.</span></p></div>

    <p><b>Note:</b> Click on each of the elements above. When clicking on the <b>div</b> element, it will alert that the div element was clicked. When clicking on the <b>p</b> element, it will return both the p and the div element, since the p element is inside the div element.
    But when clicking on the <b>span</b> element, it will only return itself, and not the p and the div element (even though its inside these elements). The event.stopPropagation() stops the click event from bubbling to the parent elements.
    </p>
    <p><b>Tip:</b> Try to remove the event.stopPropagation() line, and click on the span element again (the click event will now bubble up to parent elements).</p>

    </body>
    </html>

  • 相关阅读:
    C# 使用SMTP发送附件
    C# 获取文件名及扩展名
    邮件添加附件
    WPF 加载GIF动画
    IIS端口被占用 转载
    ReDim Preserve 的用途
    c# 构造函数执行顺序
    WriteLog
    SMS发送短信设置HttpWebRequest
    Directory.GetFiles
  • 原文地址:https://www.cnblogs.com/ch-zaizai/p/6140095.html
Copyright © 2011-2022 走看看