0

Chrome 为 div 提供了以下原型链:

element = document.getElementById("test")
<div id=​"test">​…​&lt;/div>​
element.__proto__
HTMLDivElement
element.__proto__.__proto__
HTMLElement
element.__proto__.__proto__.__proto__
Element
element.__proto__.__proto__.__proto__.__proto__
Node
element.__proto__.__proto__.__proto__.__proto__.__proto__
Object
element.__proto__.__proto__.__proto__.__proto__.__proto__.__proto__
null

在 Firefox 的情况下,我得到如下所示的内容,而 xpconnect 看起来像一些桥梁。我在 Mozilla 文档中得到了相同的原型链图片(与 Chrome 相同)。这里我的问题是如何通过遍历 HTMLDiv 元素来获取 Node 对象?如果我们有 div 元素,有人可以编写给我 Node 对象或任何其他对象(如 HTMLElement)的 js 代码吗?

图像看起来与 chrome 模型相同,但我需要代码来遍历这棵树:)

提前致谢。

图片链接

在此处输入图像描述

var element = document.getElementById("test");
element.toString();
[object HTMLDivElement]
element.__proto__.toString();
[xpconnect wrapped native prototype]
element.__proto__.__proto__.toString();
[xpconnect wrapped native prototype]
element.__proto__.__proto__.__proto__.toString();
[xpconnect wrapped native prototype]
element.__proto__.__proto__.__proto__.__proto__.toString();
[object DOM Constructor.prototype]
element.__proto__.__proto__.__proto__.__proto__.__proto__.toString();
[object Object]

我相信 element.constructor.prototype。原型和元素。原型是一样的。

4

1 回答 1

-1

一个对象的proto是一个 object ,它当然有一个对象的proto ref,所以它们都是一样的

于 2012-04-04T15:11:43.760 回答