鍍金池/ 問(wèn)答/HTML/ 關(guān)于document為什么沒(méi)有ownerDocument屬性

關(guān)于document為什么沒(méi)有ownerDocument屬性

1.所有節(jié)點(diǎn)都有的最后一個(gè)屬性是 ownerDocument,該屬性指向表示整個(gè)文檔的文檔節(jié)點(diǎn)。這種關(guān)
系表示的是任何節(jié)點(diǎn)都屬于它所在的文檔

2.JavaScript 通過(guò) Document 類(lèi)型表示文檔。在瀏覽器中,document 對(duì)象是 HTMLDocument(繼承
自 Document 類(lèi)型)的一個(gè)實(shí)例,表示整個(gè) HTML 頁(yè)面。而且,document 對(duì)象是 window 對(duì)象的一個(gè)
屬性,因此可以將其作為全局對(duì)象來(lái)訪問(wèn)。Document 節(jié)點(diǎn)具有下列特征:
? nodeType 的值為 9;
? nodeName 的值為"#document";
? nodeValue 的值為 null;
? parentNode 的值為 null;
? ownerDocument 的值為 null;
? 其子節(jié)點(diǎn)可能是一個(gè) DocumentType(最多一個(gè))、Element(最多一個(gè))、ProcessingInstruction
或 Comment。

為什么為null阿

回答
編輯回答
扯不斷

為 null 很正常啊。我本身就已經(jīng)是 document 了,所以我沒(méi)有 ownerDocument,就像沒(méi)有 parentNode 一樣。

規(guī)范里明確說(shuō)明的:

The ownerDocument attribute must run these steps:

  1. If the context object is a document, return null.
  2. Return the node document.
2017年1月8日 04:36