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

    <div id="content">
        外层div元素
        <span>内层span元素</span>
        外层div元素
    </div>
    
    <div id="msg"></div>
    $(function(){
           // 为span元素绑定click事件
        $('span').bind("click",function(event){
            var txt = $('#msg').html() + "<p>内层span元素被点击.<p/>";
            $('#msg').html(txt);
            event.stopPropagation();    //  阻止事件冒泡
        });
        // 为div元素绑定click事件
        $('#content').bind("click",function(event){
            var txt = $('#msg').html() + "<p>外层div元素被点击.<p/>";
            $('#msg').html(txt);
            event.stopPropagation();    //  阻止事件冒泡
        });
        // 为body元素绑定click事件
        $("body").bind("click",function(){
            var txt = $('#msg').html() + "<p>body元素被点击.<p/>";
            $('#msg').html(txt);
        });
    })
  • 相关阅读:
    02 树莓派的远程连接
    01 树莓派系统安装
    Python正课110 —— Django入门
    作业7 答案
    作业8
    作业7
    作业6
    文件操作
    字符编码
    基本数据类型之集合
  • 原文地址:https://www.cnblogs.com/web-leader/p/4220996.html
Copyright © 2011-2022 走看看