为什么`document.all`麻烦? [英] Why is `document.all` falsy?

查看:124
本文介绍了为什么`document.all`麻烦?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

document.all 是DOM中的一个非原始对象,是伪造的。

document.all is a non-primitive object in the DOM that is falsy.

例如,这个代码不做任何事情:

For example, this code doesn't do anything:

if (document.all) {
    alert("hello");
}

有人可以解释为什么这是吗?

Can someone explain why this is?

推荐答案

document.all 仅在Internet Explorer,webkit和Opera上可用。

document.all is available only on Internet Explorer, webkit and Opera.

在每个其他浏览器全部文档的未定义属性 object(和 undefined 被视为虚假值)

On every other browser all is an undefined property of document object (and undefined is considered as a false value)

作为历史记录:许多(真的很多)几年前, document.all 用于从Netscape Navigator通知Internet Explorer,因此如果您遇到正在检查的脚本(如果是(document.all)) 我强烈建议找一个更好的脚本:)

As historical note: many (really many) years ago document.all was used to tell Internet Explorer from Netscape Navigator so if you meet a script that is checking if (document.all) ... I strongly suggest to find a better script :)

这篇关于为什么`document.all`麻烦?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆