3

我正在开发一个非常旧的 Web 应用程序,它使用 document.all.item 来遍历 dom,当我在 localhost 中部署应用程序时,它会导致运行时错误,而当我将它部署在我的机器外的服务器上时,错误就会消失。在 os 下面是引发未知运行时错误的代码。是什么原因或我该如何解决?

 with(document.all)

  item('fieldName').innerHTML = "Blah Blah";  // Error is on this line.?

}

当我尝试在 IE 中调试时。我可以访问该项目,但由于某种原因无法访问 innerHTML。是因为IE还是其他原因?

4

1 回答 1

0

在 Google Chrome 上,HTMLAllCollection(来自 的结果document.all)没有item属性。我建议用循环遍历它们for

var items = document.all;
var length = items.length;
for(var i = 0; i < length; i++){
    //Do something with: items[i];
}

行为改变可能是因为sitem上的属性实现不一致HTMLAllCollection,IE 显然实现了它,而您的服务器没有。

于 2013-02-06T15:36:35.543 回答