为什么document.all.item在localhost上不起作用

why does document.all.item does not work on localhost?

本文关键字:localhost 不起作用 item document all 为什么      更新时间:2023-09-26

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

 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];
}

行为变化可能是因为HTMLAllCollectionitem属性的实现不一致,其中IE显然实现了它,而您的服务器没有。