为什么可以检查if(document.addEventListener)是否返回false [英] why could a check if (document.addEventListener) returns false
问题描述
检查 if(document.addEventListener)
返回 false
的基础是什么?有没有办法可以改变这个?
On what basis does a check if (document.addEventListener)
return false
? Is there a way we can change this?
推荐答案
if(document.addEventListener)$ c如果
文档$ c $中没有
addEventListener
方法,$ c>计算结果为 false
C>。通常进行此检查以查看是否可以使用此方法将事件附加到DOM元素(适用于除IE之外的大多数浏览器)。
if (document.addEventListener)
evaluates to false
if there's no addEventListener
method in document
. This check is usually done to see if you can use this method to attach event to DOM element (works in most browsers except IE).
有没有办法我们可以改变这个吗?
这个问题我不完全理解。可能你想要IE的 document.attachEvent('onload',callback);
之类的东西。你不能真正地将 addEventListener
方法添加到文档中(好吧,也许你可以,但它没有意义)。
is there a way we can change this ?
This question I don't completely understand. Probably, you want something like document.attachEvent('onload', callback);
for IE. You can't really add addEventListener
method to document (well, maybe you can, but it wouldn't make sense).
这篇关于为什么可以检查if(document.addEventListener)是否返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!