阻止冒泡

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>阻止冒泡</title>
</head>
<body>
    <div class="box1">
        <div class="box2">
            <div class="box3">内容</div>
        </div>
    </div>
    
</body>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
    $(function(){
        $('.box3').click(function(){
            alert('box33333')
            stopBubble();
        });
        $('.box2').click(function(){
            alert('box2222')
        });
        $('.box1').click(function(){
            alert('box1111')
        });

            function stopBubble(e)
        {
            if (e && e.stopPropagation)
                e.stopPropagation()
            else
                window.event.cancelBubble=true
        }
        return false
    })



</script>
</html>

 

posted @ 2017-10-24 22:42  Jinsuo  阅读(111)  评论(0编辑  收藏  举报