为什么我得到这个Javascript运行时错误? [英] Why am I getting this Javascript runtime error?

查看:126
本文介绍了为什么我得到这个Javascript运行时错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  64 var description = new Array(); 
描述[0] =...
66描述[1] =...
...
78函数init(){
79 document.getElementById('somedivid')。innerHTML = description [0];
80}
81
82 window.onload = init();

在Microsoft Internet Explorer中,它会导致以下错误...


发生运行时错误。

您是否希望调试?



Line:81

错误:未执行




第79行按预期执行。



如果第79行被注释掉了,它仍然会抛出错误。



如果我注释掉第82行,那么函数不会执行并且没有错误。

解决方案

不应该是第82行:

  window.onload = init; 

当您执行init()时,它将调用返回void的函数。您最终在页面加载之前调用该函数。


I've got the following JavaScript on my web page...

64    var description = new Array();
65    description[0] = "..."
66    description[1] = "..."
...
78    function init() {
79        document.getElementById('somedivid').innerHTML = description[0];
80    }
81
82    window.onload = init();

In Microsoft Internet Explorer it causes the following error...

A Runtime Error has occurred.
Do you wish to debug?

Line: 81
Error: Not implemented

Line 79 executes as expected.

If line 79 is commented out, it still throws the error.

If I comment out line 82, then the function does not execute and there is no error.

解决方案

Shouldn't line 82 read:

window.onload = init;

When you do "init()" it's a call to a function that returns void. You end up calling that function before the page loads.

这篇关于为什么我得到这个Javascript运行时错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆