我正在开发一个非常古老的网络应用程序,它使用 document.all.item 来迭代 dom 并 当我在本地主机中部署应用程序时,它会导致运行时错误,而当我将其部署在计算机外部的服务器上时,错误就会消失。下面是抛出未知运行时错误的代码。原因是什么或者我该如何解决它?
with(document.all)
item('fieldName').innerHTML = "Blah Blah"; // Error is on this line.?
}
当我尝试在 IE 中调试时。我可以访问该项目,但由于某种原因无法访问innerHTML。是IE的原因还是其他原因?
最佳答案
在 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];
}
行为更改可能是因为 HTMLAllCollection
上 item
属性的实现不一致,其中 IE 显然实现了它,而您的服务器没有实现。
关于javascript - 为什么 document.all.item 在本地主机上不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14732750/