gpt4 book ai didi

javascript - 为什么 dom 元素作为窗口对象的属性存在?

转载 作者:太空狗 更新时间:2023-10-29 14:18:06 25 4
gpt4 key购买 nike

<分区>

如果我这样写 html:

<div id="foo">Foo<div>

window.foo 返回一个 dom 元素,window.document.getElementById("foo") === window.foo 返回 true.

这是为什么呢?为什么每个人都使用 getElementById

旁注:为什么在 IE7/8 中禁止重写 window.foo?如果我设置 window.foo = "bar" 会发生什么?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com