<script>
function test(e){
e = e || window.event;
if (window.event) {
e.cancelBubble = true;
} else {
e.stopPropagation();
}
alert(1);
}
</script>
<div style="background: #666699;width: 300px;height: 200px;border: 0.2cm #CCCCFF solid;cursor: pointer;position:absolute;top: 100px;left:100px;" onclick="test(event)"><div style="background: #66EE99;width: 100px;height: 80px;border: 0.2cm #FFFCFF solid;cursor: pointer;position:absolute;top: 100px;left:100px;"></div></div>为什么alert(1);一直被执行(就算我点击里面那个div)

解决方案 »

  1.   

    你研究一下这个<script>
    function test(e,a){
    e = e || window.event;
    if (window.event) {
    e.cancelBubble = true;
    } else {
    e.stopPropagation();
    }
    if(!a) alert(1);
    }
    </script>
    <div style="background: #666699;width: 300px;height: 200px;border: 0.2cm #CCCCFF solid;cursor: pointer;position:absolute;top: 100px;left:100px;" onclick="test(event)">
    <div onclick="test(event,1)" style="background: #66EE99;width: 100px;height: 80px;border: 0.2cm #FFFCFF solid;cursor: pointer;position:absolute;top: 100px;left:100px;"></div></div>