1

我有以下代码来填充数组。

matches = $('.cultureShortNameColumn');
numMatches = matches.length;

cultures = [];

for (var i = 0; i < numMatches; i++) {
  cultures[i] = matches[i].childNodes[0].textContent;
}

此代码在 FireFox、Chrome 和 IE 9 及更高版本中完美运行。

但是,在 IE 8 及更低版本中,我在调试器中看到,以下表达式的计算结果如下:

matches[i]                          {...}   DispHTMLTableCell
matches[0].childNodes                   {...}   DispDOMChildrenCollection
matches[0].childNodes[0]            {...}   DispHTMLDOMTextNode
matches[0].childNodes[0].textContent    undefined   Undefined

但是,当我matches[0].childNodes[0]在调试器的 Watches 窗口中展开局部变量时,它确实具有textContent读取有效值的属性。

4

1 回答 1

0

好的,我在发布这个问题后做了一点谷歌搜索,顶部链接中有一个答案:

答案是使用nodeValue而不是textContent.

我试过了,它有效。

matches[0].childNodes[0].nodeValue;
于 2013-10-24T15:16:40.803 回答