肯定是在alert之前就出错了,下个firebug跟断点调试调试吧

解决方案 »

  1.   

    ???????????不明白,没用过firebug还是请各位指教
      

  2.   

    急死我了,怎么连在fixefox下连冒泡也阻止不了呢/如下:
    <html>
    <head>
    <script language = "javascript" defer = "defer">
    var EventUtil = new Object;//事件对像
    EventUtil.getEvent = function()
    {
    if(window.event)
    {
    return (window.event);
    }
    else
    {
    return EventUtil.getEvent.caller.arguments[0];
    }
    }
    EventUtil.formatEvent = function(oEvent)
    {
    if(oEvent.type == "mouseout")
    {
    oEvent.relatedTarget = oEvent.toElement;//鼠标事件中鼠标正在进入的元素
    }
    else if(oEvent.type == "mouseover")
    {
    oEvent.relatedTarget = oEvent.fromElement;//鼠标事件中鼠标离开的元素
    }
    oEvent.stopPropagation = function()
    {
    this.cancelBubble = true;
    }
    }
    function qq()
    {
    alert('div');
    oEvent = EventUtil.getEvent();
    EventUtil.formatEvent(oEvent);
    oEvent.stopPropagation();//此时阻止冒泡也不成功在ie下成功,在firefox下失败还是继续冒泡

                 
    }
    </script>
    </head>
    <body onclick = "alert('body')">
    <div id="div1" onclick = qq() style="width:100px;height:100px;background-color:red">test for test</div>
    </body>
    </html>
      

  3.   

    就是说出现了代码在两个浏览器上不兼容的情况,在IE上可以,在FF上没出就肯定是在ALERT之间就出错了,你可以把调的那两个方法TRY起来看看,看有没异常,
    最土的检测方法就是在之前不停的ALERT,在出错地方之前的ALERT是可以出来的.
      

  4.   

    firebug是firefox的一个插件,可以断点调试js,查看DOM等,非常好用,做Web开发的怎么能没有呢?
      

  5.   

    最土的调试方法就是,在你认为可能有错的地方都写上alert( "某某行" );然后你运行看哪个alert没出来,那就是在他之前就出错了不过最好还是用调试工具,IE用VS,火狐用FireBug
      

  6.   

    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body><script language = "javascript" defer = "defer">
            var sUserAgent = navigator.userAgent;
                var isIE = sUserAgent.indexOf("compatible") > -1 && sUserAgent.indexOf("MSIE") > -1;     var EventUtil = new Object;//事件对像
            EventUtil.getEvent = function()
            {
                if(window.event)
                {
                    return this.formatEvent(window.event);
                }
                else
                {
                    return EventUtil.getEvent.caller.arguments[0];
                }
            }
            EventUtil.formatEvent = function(oEvent)
            {
                if(isIE)
                {                if(oEvent.type == "mouseout")
                    {
                        oEvent.relatedTarget = oEvent.toElement;//鼠标事件中鼠标正在进入的元素
                    }
                    else if(oEvent.type == "mouseover")
                    {
                        oEvent.relatedTarget = oEvent.fromElement;//鼠标事件中鼠标离开的元素
                    }
                }
                return oEvent;//我不明白为什么把这句话去掉,会报错,为什么啊?别的地方也没有用到返回的oEvent啊?        }
                function qq()
                {
                    oEvent = EventUtil.getEvent();
                    //EventUtil.formatEvent(oEvent);
                    alert(oEvent.relatedTarget);//这个地方在firefox下没有反应
                                 
                }
    </script>
     <div id="div1" onmouseout =qq(event) style="width:100px;height:100px;background-color:red">test for test</div>
    </body>
    </html>这才对啊大哥