JavaScript: The Definitive Guide, Sixth Editio javaScript权威指南(第6版) pdf 文字版-文字版, javascript电子书, 和javascript 有关的电子书:

15.6.1 Creating Nodes

15.6.1 Creating Nodes

As shown in the code above, you can create new Element nodes with the createElement() method of the Document object. Pass the tag name of the element as the method argument: this name is case-insensitive for HTML documents and case-sensitive for XML documents.

Text nodes are created with a similar method:

var newnode = document.createTextNode("text node content");

Document defines other factory methods, such as the infrequently used createComment(), as well. We’ll use the createDocumentFragment() method in §15.6.4 . When working with documents that use XML namespaces, you can use createElementNS()to specify both the namespace URI and the tag name of the Element to be created.

Another way to create new document nodes is to make copies of existing ones. Every node has a cloneNode() method that returns a new copy of the node. Pass true to recursively copy all descendants as well, or false to only make a shallow copy. In browsers other than IE, the Document object also defines a similar method named importNode(). If you pass it a node from another document, it returns a copy suitable for insertion into this document. Pass trueas the second argument to recursively import all descendants.

友情链接It题库(| 版权归yishouce.com所有| 友链等可联系|粤ICP备16001685号-1