HTML是顺序读取文件的.你把"DIV1"对象放在下面,当加载页面时是首先读取脚本的.
oDiv.onclick=handleEvent;//这行报错.又没放在函数块里,自然读不到什么对象了

解决方案 »

  1.   

    <div id="div1">aaaaaaaa
    </div><script>
    function handleEvent(oEvent){
    if(oEvent.type=="click"){
    alert("click");
    }else if(oEvent.type=="mouseover"){
    alert("Mouse Over");
    }else{
    alert("aaaa");
    }


    }
    var oDiv=document.getElementById("div1");
    oDiv.onclick=handleEvent;//这行报错.
    oDiv.onmouseover=handleEvent;
    </script>
      

  2.   

    從你的機器上能夠正常運行嗎?我這個還是抱錯在
    if(oEvent.type=="click"),現在報 'type'為null或不是一個物件.
      

  3.   

    hehe -物件-
    <script>
    function handleEvent(oEvent){
    if(oEvent.type=="click"){
    alert("click");
    }else if(oEvent.type=="mouseover"){
    alert("Mouse Over");
    }else{
    alert("aaaa");
    }
    }
    var oDiv=document.getElementById("div1");
    oDiv.onclick=function(){handleEvent(event)};
    oDiv.onmouseover=function(){handleEvent(event)};
    </script>