gpt4 book ai didi

javascript - 为什么我们使用 typeof XMLHttpRequest ! ="undefined"?什么是未定义的?

转载 作者:行者123 更新时间:2023-11-30 08:35:55 27 4
gpt4 key购买 nike

为什么我们使用 typeof XMLHttpRequest !="undefined"

什么是 undefined 我不明白那里的 undefined 是什么?

 if (typeof XMLHttpRequest != "undefined")
{
xmlHttp= new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}

最佳答案

这些类型的检查适用于非常旧版本的 Internet Explorer(准确地说是 IE6 及更低版本)。

有几种方法可以检测浏览器是否支持XMLHttpRequest。使用 typeof SomeObject 只是其中一种方法。您可能还会看到...

if ("XMLHttpRequest" in window) { ... }

或者直接向上

if (window.XMLHttpRequest) { ... }

关于javascript - 为什么我们使用 typeof XMLHttpRequest ! ="undefined"?什么是未定义的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31444627/

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