为什么是document.all'false'?
Why is document.all 'false'?
所以我在 JavaScript 中使用 document
作为使用 document.getElementById
的替代方法。但为什么 document.all
等于 null
?我运行几个命令来证明它更'falsy'。
document.all // HTMLAllCollection[1276]
document.all[0] // <html>...</html>
typeof document.all // 'undefined'
!{} // false. works correctly
!document.all // true! WTF
这是什么?其他对象 工作正常。 document.all
对象发生了什么事?坏了吗?
document.all
是IE引入的non-standardAPI。使用它不是好的做法。
为了与依赖它的网站兼容,其他一些浏览器已经引入了对它的支持。
一些使用它的网站依赖于测试 document.all
的存在来确定浏览器 是否是 IE 并使用它来假设浏览器有一堆IE 提供的错误和其他 non-standard API。
添加了兼容性支持的浏览器return一个虚假的值,这样它们就不会被错误地识别为 IE(并通过其他无法在它们上运行的代码)。
所以我在 JavaScript 中使用 document
作为使用 document.getElementById
的替代方法。但为什么 document.all
等于 null
?我运行几个命令来证明它更'falsy'。
document.all // HTMLAllCollection[1276]
document.all[0] // <html>...</html>
typeof document.all // 'undefined'
!{} // false. works correctly
!document.all // true! WTF
这是什么?其他对象 工作正常。 document.all
对象发生了什么事?坏了吗?
document.all
是IE引入的non-standardAPI。使用它不是好的做法。
为了与依赖它的网站兼容,其他一些浏览器已经引入了对它的支持。
一些使用它的网站依赖于测试 document.all
的存在来确定浏览器 是否是 IE 并使用它来假设浏览器有一堆IE 提供的错误和其他 non-standard API。
添加了兼容性支持的浏览器return一个虚假的值,这样它们就不会被错误地识别为 IE(并通过其他无法在它们上运行的代码)。