Visit Mozilla.org

DOM:document

From MDC

« Gecko DOM 参考

DOM 中, document 对象提供了一个表示 HTMLXHTMLXML 文档的一般方法。Document 对象实现了一般 DOM 核心文档 接口。

除了一般的 DOM 核心文档接口, HTML document 还实现了 DOM HTMLDocument 接口, 它是个用于处理 HTML 文档的更为特殊化的接口(例如, document.cookie, document.alinkColor)。此处列出的属性和方法有部分属于这一更为特殊化的接口,用星号(*)标出。

document 包含于 window 对象内,并可能包含任意多个 elements

document 接口提供了对 document 类型、它的颜色和格式、插件和 applets 等的访问,也提供了创建和维护所有文档的子结点或者 BODY 和 TABLE 之类元素的方法。

目录


[编辑] 属性

document.alinkColor* Deprecated
Returns or sets the color of active links in the document body.
document.anchors*
anchors returns a list of all of the anchors in the document.
document.applets*
applets returns an ordered list of the applets within a document.
document.bgColor* Deprecated
bgColor gets/sets the background color of the current document.
document.body*
body returns the BODY node of the current document.
document.characterSet
Returns the character set being used by the document.
document.compatMode*
Indicates whether the document is rendered in Quirks or Strict mode.
document.contentType
Returns the Content-Type from the MIME Header of the current document.
document.cookie*
Returns a semicolon-separated list of the cookies for that document or sets a single cookie.
document.defaultView
Returns a reference to the window object.
document.designMode*
designMode gets/sets WYSYWIG editing capability of Midas. It can only be used for HTML documents.
document.doctype
Returns the Document Type Definition (DTD) of the current document.
document.documentElement
Returns the Element that is a direct child of document. For HTML documents, this is normally the HTML element.
document.documentURIObject New in Firefox 3
Returns the Template:interface object representing the URI of the document. This property only has special meaning in privileged JavaScript code (with UniversalXPConnect privileges).
document.domain*
domain returns the domain of the current document.
document.embeds*
embeds returns a list of the embedded OBJECTS within the current document.
document.fgColor* Deprecated
fgColor gets/sets the foreground color, or text color, of the current document.
document.firstChild
firstChild returns the first node in the list of direct children of the document. (See also firstChild for the general element property.)
document.forms*
forms returns a list of the FORM elements within the current document.
document.height*
height gets/sets the height of the current document.
document.images*
images returns a list of the images in the current document.
document.implementation*
Returns the DOM implementation associated with the current document.
document.lastModified*
Returns the date on which the document was last modified.
document.linkColor* Deprecated
Gets/sets the color of hyperlinks in the document.
document.links*
Returns a list of all the hyperlinks in the document.
document.location*
Returns the URI of the current document.
document.namespaceURI
Returns the XML namespace of the current document.
document.plugins*
Returns a list of the available plugins.
document.popupNode
Returns the node upon which a popup was invoked (XUL documents only).
document.referrer*
Returns the URI of the page that linked to this page.
document.styleSheets*
Returns a list of the stylesheet objects on the current document.
document.title*
Returns the title of the current document.
document.tooltipNode
Returns the node which is the target of the current tooltip.
document.URL
Returns a string containing the URL of the current document.
document.vlinkColor* Deprecated
获取/设置已访问过的超级链接的颜色。
document.width*
Returns the width of the current document.

[编辑] 方法

document.clear* Deprecated
In majority of modern browsers, including recent versions of Firefox and Internet Explorer, this method does nothing.
document.close*
Closes a document stream for writing.
document.createAttribute
Creates a new attribute node and returns it.
document.createCDATASection
Creates a new CDATA node and returns it.
document.createComment
Creates a new comment node and returns it.
document.createDocumentFragment
Creates a new document fragment.
document.createElement
用指定的标签名创建一个新元素。
document.createElementNS
用指定的标签名和命名空间 URI 创建一个新元素。
document.createEntityReference
Creates a new entity reference object and returns it.
document.createEvent
Creates an event.
document.createNSResolver
Creates an XPathNSResolver.
document.createProcessingInstruction
Creates a new processing instruction element and returns it.
document.createRange
Creates a Range object.
document.createTextNode
创建一个文本结点。
document.createTreeWalker
Creates a TreeWalker object.
document.elementFromPoint New in Firefox 3
Returns the element visible at the specified coordinates.
document.evaluate
计算一个XPath表达式的值。
document.execCommand*
Executes a Midas command.
document.getElementById
Returns an object reference to the identified element.
document.getElementsByName
返回一个具有给定名称的元素的列表。
document.getElementsByTagName
返回一个具有给定标签名的元素的列表。
document.getElementsByTagNameNS
Returns a list of elements with the given tag name and namespace.
document.importNode
Returns a clone of a node from an external document.
document.loadOverlay
New in Firefox 1.5 Loads a XUL overlay dynamically. This only works in XUL documents.
document.open*
Opens a document stream for writing.
document.queryCommandEnabled*
Returns true if the Midas command can be executed on the current range.
document.queryCommandIndeterm*
Returns true if the Midas command is in a indeterminate state on the current range.
document.queryCommandState*
Returns true if the Midas command has been executed on the current range.
document.queryCommandValue*
Returns the current value of the current range for Midas command. As of Firefox 2.0.0.2, queryCommandValue will return an empty string when a command value has not been explicitly set.
document.write*
Writes text to a document.
document.writeln*
Write a line of text to a document.

[编辑] Event Handlers

Firefox 3 introduces two new events: "online" and "offline". These two events are fired on the <body> of each page when the browser switches between online and offline mode. Additionally, the events bubble up from document.body, to document, ending at window. Both events are non-cancellable (you can't prevent the user from coming online, or going offline). For more info see Online_and_offline_events.

document.ononline New in Firefox 3
Returns the event handling code for the online event.
document.onoffline New in Firefox 3
Returns the event handling code for the offline event.