javascript 现在 document.all 和 document.layers 已过时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15854504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 02:20:09  来源:igfitidea点击:

are document.all and document.layers obsolete now

javascript

提问by Paul

I am going through some (old?) native javascript and I encountered a separation of document.getElementById, document.all and document.layers.

我正在使用一些(旧的?)原生 javascript,我遇到了 document.getElementById、document.all 和 document.layers 的分离。

From what I know, document.all and document.layers are obsolete now, but I just wanted to make sure.

据我所知, document.all 和 document.layers 现在已经过时了,但我只是想确定一下。

回答by Guffa

Yes, they are obsolete.

是的,它们已经过时了。

The document.allcollection is specific to Internet Explorer. The document.layerscollection was specific to Netscape. Neither is in the standards.

document.all集合特定于 Internet Explorer。该document.layers集合是特定于 Netscape 的。两者都不在标准中。

Today we use document.getElementByIdinstead.

今天我们用document.getElementById代替。

See also: https://developer.mozilla.org/en-US/docs/Mozilla_Web_Developer_FAQ#JavaScript_doesn.E2.80.99t_work.21_Why.3F

另见:https: //developer.mozilla.org/en-US/docs/Mozilla_Web_Developer_FAQ#JavaScript_doesn.E2.80.99t_work.21_Why.3F

回答by ZER0

Yes, they are. They comes from a period where Internet Explorer 4 and Netscape 4.x were the main browsers: document.layerswas used by Netscape, and document.allfrom IE. The first is definitely unused anymore, where I guess document.allis still used for legacy in IEs.

对,他们是。它们来自 Internet Explorer 4 和 Netscape 4.x 是主要浏览器的时期:document.layers由 Netscape 和document.allIE 使用。第一个肯定不再使用了,我猜document.all它仍然用于 IE 中的遗留。