zoukankan      html  css  js  c++  java
  • (转)JavaScript 冒泡实例与阻止冒泡方法

    <html>
    <head>
    <style type="text/css">
    body{background:#000;color:#FFF}
    form{background:#F00}
    </style>
    </head>
    <body>
    <script type="text/javascript" src="jquery.js"></script>
    <form>
    <input type="button" value="button">
    </form>
    <script type="text/javascript">
    $(window).click(function () {alert("window");}); 
    $(document).click(function () {alert("document");}); 
    $("form").click(function () {alert("form");});
    $("input").click(function () {alert("button");}); 
    </script>
    </body>
    </html>

    阻止气泡:
    <html>
    <head>
    <style type="text/css">
    body{background:#000;color:#FFF}
    form{background:#F00}
    </style>
    </head>
    <body>
    <script type="text/javascript" src="jquery.js"></script>
    <form>
    <input type="button" value="button">
    </form>
    <script type="text/javascript">
    $(window).click(function (even) {even.stopPropagation();alert("window");}); 
    $(document).click(function (even) {even.stopPropagation();alert("document");}); 
    $("form").click(function (even) {even.stopPropagation();alert("form");});
    $("input").click(function (even) {even.stopPropagation();alert("button");}); 
    </script>
    </body>
    </html>

    $('span').onclick = function(e)

    { $('test').style.display = 'block';

    e = e || window.event;

    if (e.stopPropagation)  //W3W

    { e.stopPropagation(); }

    else { e.cancelBubble = true; } // Ie阻止事件冒泡

    }

    地址:http://hi.baidu.com/lostsolar/blog/item/07c659f54088f569dcc47427.html

  • 相关阅读:
    nginx编译安装
    使用scp命令,不同服务器之间拷备文件
    cpu负载过高排查与解决
    Docker安装
    sftp安装
    nginx登陆验证 [done]
    git常用命令
    python常见问题记录
    升级openssl
    rsync使用
  • 原文地址:https://www.cnblogs.com/wdw31210/p/2540770.html
Copyright © 2011-2022 走看看