1

TypeError: Unable to get value of the property 'childNodes': object is null or undefinedundefined

为了支持 IE8,对我的应用程序进行了一长串修改后,包括:通过 W3C 验证器以编译形式运行所有视图,设置xdomain.js 代理以支持 CORS API 调用,进行一些常规重组等。我很失望地发现 IE8 仍然向我抛出这个奇怪的错误,而 IE9 工作得很好。

更改 Angular-seo 包以防止它在客户端是 IE 浏览器时运行。

关于它可能是什么的任何想法?

4

3 回答 3

2

确保所有标签都正确关闭。我只是花了几个小时试图找出问题所在,直到我在我的代码中注意到这一点:

<span>some text<span>

我终于意识到我没有<span>正确关闭标签。在那之后,一切都正常了。

于 2014-10-04T04:59:19.833 回答
1

没有您正在运行的代码,这有点困难。但是有一个用于调试的命令。首先,您需要确定哪个变量可能不包含对象[即“对象为空或未定义”]。例如,父母,那么你可以使用

//next look to see if parent is something
if('undefined'==(typeof parent)) alert("variable empty:parent");

一旦你发现你期望成为一个对象的空的东西,你就可以从那里追溯。还可以使用浏览器调试工具,来识别错误的行号。

通常,如果使用子节点,您可能没有正确的级别,或者您需要作为数组访问,即您需要类似的东西。

parent.childNodes[0].childNodes[0].value

在 IE 中,您还要处理不受支持的功能。所以 getElementById 会起作用,但其他一些类似的不会。再次 typeof 可能很有用。

//next ensure function supported
if( 'undefined'==(typeof document.getElementsByClassName) ){
    alert("Not Supported");                  // notice ^ no () required here
    //...add code to handle differently when not supported
}

这可能会揭示您是否可以使用某个功能

于 2013-10-30T15:09:37.350 回答
1

IE8 太旧且不符合标准,它不支持 childNodes[]。http://quirksmode.org/dom/core/#t70

于 2015-03-31T19:14:18.557 回答