首页 > Web开发 > 详细

js中阻止事件冒泡

时间:2015-07-03 12:34:44      阅读:197      评论:0      收藏:0      [点我收藏+]
<html>
        <head>
                <title>js阻止时间冒泡</title>
        </head>
        <style>
                #bubble{width:300px;height:300px;background:red;}
                #bubble2{width:200px;height:200px;background:green;}
                #bubble3{width:100px;height:100px;background:blue;}
        </style>
        <body>
                <div id="bubble" onclick="bubble(this, event)">
                <div id="bubble2" onclick="bubble(this, event)">
                        <div id="bubble3" onclick="bubble(this, event)">this one</div>
                                this two
                        </div>
                        this three
                </div>
        <body>
</html>
<script>
    //阻止事件冒泡
    function stopEventBubble(event){
        var e=event || window.event;
        if (e && e.stopPropagation){
            e.stopPropagation();
        }
        else{
            e.cancelBubble=true;
        }
    }
    
    function bubble(obj, evt){
        alert(obj.id);
        stopEventBubble(evt);
    }
</script>

js中阻止事件冒泡

原文:http://my.oschina.net/tpythoner/blog/473925

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!