在大多数浏览器中,document.createElement("div") instanceof HTMLElement
将是 true
。要支持某些 IE 浏览器,您必须执行 document.createElement("div") instanceof (window.HTMLElement||window.Element)
以正确检查它是否是一个元素。
这在 IE7 之前有效,其中 window.HTMLElement
和 window.Element
是 undefined
,因此导致以下错误。
Invalid operand to 'instanceof': Function expected
我尝试搜索 window
对象,但它没有列出内置类,我也尝试使用 Object.getPrototypeOf
失败,因为它不存在。 Searching on Google 没有给出想要的结果。
我也不想使用 .nodeType
,因为那样 {nodeType:1}
会被错误地视为一个元素。
我应该用什么来检查 IE7 中的元素?