问题描述
HTMLElement
和 Element
有什么区别?
document.createElement("div")元素实例
给出真实的
document.createElement("div")实例
给出了真
HTMLElement ===元素
给出错误
推荐答案
HTMLElement
是 Element
,如对DOM级别2的HTML扩展核心规格:
interface HTMLElement : Element {
attribute DOMString id;
attribute DOMString title;
attribute DOMString lang;
attribute DOMString dir;
attribute DOMString className;
};
Element
(根据规范)指的是 DOM核心2级规范(还有另一个 DOM核心规范(工作草案).
Element
(per specification) refers to the Element
interface as it is defined in the DOM Core Level 2 specification (there is also another DOM Core specification (working draft) though).
更新:这里有很多规范,而且尚不清楚哪个浏览器使用哪个浏览器(对我来说).
Update: There are a lot of specifications out there and it is not totally clear which browsers use which one (to me).
也许其他人有更多的见识...
Maybe someone else has more insight...
但是无论如何, Element
是一个比 HTMLElement
更通用的接口,后者是从前者继承的.
But in any case, Element
is a more generic interface than HTMLElement
and the latter inherits from the former.
更新2:一种查看继承结构的好方法是对任何元素执行 console.dir(elementReference)
(在Chrome/Safari中工作,需要Firebug才能实现)Firefox).
Update 2: A nice way to see the inheritance structure is to execute console.dir(elementReference)
for any element (works in Chrome/Safari, needs Firebug for Firefox).
这篇关于HTMLElement和Element之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!