奇怪的IE javascript错误

时间:2009-07-15 17:42:39

标签: javascript internet-explorer

出于某种原因,当我在IE中运行游戏时,它会在预加载期间停止。我打开了IE8的调试器,它在这行上失败了,抱怨一些运行时错误。

document.getElementById("mainpreloaderscreen").innerHTML=loaded+"/"+total+"<br><button onclick=\"gamepreload('all')\">load all (not  recomended)</button>";

为什么IE会这样做,我该如何解决?

继承整个职能

    function gamepreload(item)
{
loaded++;
total=18;
document.getElementById("mainpreloaderscreen").innerHTML=loaded+"/"+total+"<br><button onclick=\"gamepreload('all')\">load all (not  recomended)</button>";

if(item==0||item=='all'){gamepreloadstuff[0]=new Image();   gamepreloadstuff[0].onload=function(){gamepreload(1)};  gamepreloadstuff[0].src="images/menusignpoll.jpg";document.getElementById("img-menusignpoll").src=gamepreloadstuff[0].src;                                      }
if(item==1||item=='all'){gamepreloadstuff[1]=new Image();   gamepreloadstuff[1].onload=function(){gamepreload(2)};  gamepreloadstuff[1].src="images/menusignnewbutton.png";document.getElementById("img-menusignnewbutton").src=gamepreloadstuff[1].src;                            }
if(item==2||item=='all'){gamepreloadstuff[2]=new Image();   gamepreloadstuff[2].onload=function(){gamepreload(3)};  gamepreloadstuff[2].src="images/menusignnewbutton-glowing.png";                                                                                                 }
if(item==3||item=='all'){gamepreloadstuff[3]=new Image();   gamepreloadstuff[3].onload=function(){gamepreload(4)};  gamepreloadstuff[3].src="images/menusignresumebutton.png";document.getElementById("img-menusignresumebutton").src=gamepreloadstuff[3].src;                      }
if(item==4||item=='all'){gamepreloadstuff[4]=new Image();   gamepreloadstuff[4].onload=function(){gamepreload(5)};  gamepreloadstuff[4].src="images/menusignresumebutton-glowing.png";                                                                                              }
if(item==5||item=='all'){gamepreloadstuff[5]=new Image();   gamepreloadstuff[5].onload=function(){gamepreload(6)};  gamepreloadstuff[5].src="images/menusignhelpbutton.png";document.getElementById("img-menusignhelpbutton").src=gamepreloadstuff[5].src;                          }
if(item==6||item=='all'){gamepreloadstuff[6]=new Image();   gamepreloadstuff[6].onload=function(){gamepreload(7)};  gamepreloadstuff[6].src="images/menusignhelpbutton-glowing.png";                                                                                                }
if(item==7||item=='all'){gamepreloadstuff[7]=new Image();   gamepreloadstuff[7].onload=function(){gamepreload(8)};  gamepreloadstuff[7].src="images/menusignscoresbutton.png";document.getElementById("img-menusignscoresbutton").src=gamepreloadstuff[7].src;                      }
if(item==8||item=='all'){gamepreloadstuff[8]=new Image();   gamepreloadstuff[8].onload=function(){gamepreload(9)};  gamepreloadstuff[8].src="images/menusignscoresbutton-glowing.png";                                                                                              }
if(item==9||item=='all'){gamepreloadstuff[9]=new Image();   gamepreloadstuff[9].onload=function(){gamepreload(10)}; gamepreloadstuff[9].src="images/menusignoptionsbutton.png";document.getElementById("img-menusignoptionsbutton").src=gamepreloadstuff[9].src;                    }
if(item==10||item=='all'){gamepreloadstuff[10]=new Image(); gamepreloadstuff[10].onload=function(){gamepreload(11)};    gamepreloadstuff[10].src="images/menusignoptionsbutton-glowing.png";                                                                                            }
if(item==11||item=='all'){gamepreloadstuff[11]=new Image(); gamepreloadstuff[11].onload=function(){gamepreload(12)};    gamepreloadstuff[11].src="images/menusigncreditsbutton.png";document.getElementById("img-menusigncreditsbutton").src=gamepreloadstuff[11].src;                  }
if(item==12||item=='all'){gamepreloadstuff[12]=new Image(); gamepreloadstuff[12].onload=function(){gamepreload(13)};    gamepreloadstuff[12].src="images/menusigncreditsbutton-glowing.png";                                                                                            }
if(item==13||item=='all'){gamepreloadstuff[13]=new Image(); gamepreloadstuff[13].onload=function(){gamepreload(14)};    gamepreloadstuff[13].src="images/menusignleaves.png";document.getElementById("img-menusignleaves").src=gamepreloadstuff[13].src;                                }
if(item==14||item=='all'){gamepreloadstuff[14]=new Image(); gamepreloadstuff[14].onload=function(){gamepreload(15)};    gamepreloadstuff[14].src="images/menubox.png";document.getElementById("img-menubox").src=gamepreloadstuff[14].src;                                              }
if(item==15||item=='all'){gamepreloadstuff[15]=new Image(); gamepreloadstuff[15].onload=function(){gamepreload(16)};    gamepreloadstuff[15].src="images/menusavedindents.png";document.getElementById("img-menusavedindents").src=gamepreloadstuff[15].src;                                                }
if(item==16||item=='all'){gamepreloadstuff[16]=new Image(); gamepreloadstuff[16].onload=function(){gamepreload(17)};    gamepreloadstuff[16].src="images/mainbackbutton.png";document.getElementById("img-mainbackbutton").src=gamepreloadstuff[16].src;                                                }
if(item==17||item=='all'){gamepreloadstuff[17]=new Image(); gamepreloadstuff[17].onload=function(){gamepreload(18)};    gamepreloadstuff[17].src="images/mainbackbutton-glowing.png";                                                                                           }
if(item==18||item=='all'){document.getElementById("mainpreloaderscreen").style.display="none";}
}

IE 8调试器说“打破JSruntime错误 - (n

适用于FF和chrome

1 个答案:

答案 0 :(得分:1)

我的猜测是,当您拨打该电话时,未加载DOM。将该代码附加到onload事件。