3

document.all.item を使用して dom を反復処理する非常に古い Web アプリに取り組んでおり、アプリケーションを localhost にデプロイするとランタイム エラーが発生し、マシン外のサーバーにデプロイするとエラーが消えます。以下は、不明なランタイム エラーをスローするコードです。理由は何ですか、またはそれを解決するにはどうすればよいですか?

 with(document.all)

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

}

IEでデバッグしようとしたとき。アイテムにはアクセスできますが、何らかの理由で innerHTML にアクセスできません。IEか何かのせいでしょうか?

4

1 に答える 1

0

On Google Chrome, HTMLAllCollection (The result from document.all) has no item property. I'd suggest looping through them with an for loop:

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

The behaviour change might be because of inconsistent implementation of a item property on HTMLAllCollections, where IE apparently does implement it, and your server doesn't.

于 2013-02-06T15:36:35.543 に答える