日期:2014-05-16  浏览次数:20352 次

js的事件冒泡,为什么IE好使,firebox不好使,怎么改?
JScript code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="gb2312">
<head>
<title> test</title>
<script src="jquery.min.js"></script>
<script type="text/javascript">
    function show_s(evt){
        $('#test').show();
        var e=(evt)?evt:window.event;
        if (window.event) {
            e.cancelBubble=true;
        } else {
            e.stopPropagation();
        }
    }
    function init(){
        $("body").bind("click", function(){
          $('#test').hide();
        }); 
    }
    $(document).ready(function(){
        init();
    });
</script>
</head>
<body>
<div onclick="show_s();">dddddddddddddddddddddddddd</div>
<div id="test" style="display:none;">mmmmmmmmmmmmmmmmmmm</div>
</body>
</html> 


------解决方案--------------------
这是我以前收藏的阻止事件冒泡的代码,在ff和ie下都可以的
JScript code
//阻止事件冒泡
    var ev = window.event || arguments.callee.caller.arguments[0];
    if (window.event) {
        ev.cancelBubble = true;
    }
    else {
        ev.stopPropagation();
    }
    //