XML DOM importNode() 方法

Document Object Reference Manual

定义和用法

importNode() 方法把一个节点从另一个文档复制到该文档以便应用。

语法:

importNode(importedNode,deep)
Parameter Description
importedNode The node to be imported.
deep If true, all descendant nodes of the importedNode node will also be recursively copied.

Return value

importedNode a copy (and possibly its descendants) of its ownerDocument attribute is set to the document.

throws

if importedNode is a Document node or DocumentType node, and the method will throw a NOT_SUPPORTED_ERR code DOMException exception, because these types of nodes cannot be imported.

Description

The parameter of this method is a node defined in another document, and the return value is a copy of the node suitable for insertion into the document. If deep If the value is true, then all descendant nodes of the node will also be copied. In any case, the original node and its descendant nodes will not be modified.

The ownerDocument attribute of the returned copy is set to the current document, but the parentNode attribute is null because it has not been inserted into the document yet. Event listener functions registered on the original node or tree will not be copied.

When importing Element nodes, only attributes explicitly set in the source document will be imported. When importing Attr nodes, the specified attribute of its will be automatically set to true.

See

Node.cloneNode()

Document Object Reference Manual