jQuery如何防止这种冒泡事件发生

2020-05-22 21:58:11易采站长站整理

        return false;
    });
    $(‘#content’).bind(“click”,function(event){
        var txt = $(‘#msg’).html() + “<p>外层div元素被点<p/>”;
        $(‘#msg’).html(txt);
        return false;
    });
    $(“body”).bind(“click”,function(){
        var txt = $(‘#msg’).html() + “<p>body元素被点<p/>”;
        $(‘#msg’).html(txt);
    });
})
</script>

jQuery对DOM的事件触发具有冒泡特性。有时利用这一特性可以减少重复代码,但有时候我们又不希望事件冒泡。这个时候就要阻止 jQuery.Event冒泡。