XML DOM createComment() 方法


Document 對象參考手冊 Document 對象

定義和用法

createComment() 方法創建注釋節點。

該方法返回 Comment 對象。

語法

createComment(data)

參數 描述
data 字串,這個字串為節點規定數據。


實例

下麵的代碼片段使用 loadXMLDoc() 把 "books.xml" 載入 xmlDoc 中,並把注釋節點添加到 <book> 元素:

實例

xmlDoc=loadXMLDoc("books.xml"); x=xmlDoc.getElementsByTagName('book'); for (i=0;i<x.length;i++) { newComment=xmlDoc.createComment("Revised April 2008"); x[i].appendChild(newComment); } for (i=0;i<x.length;i++) { document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue); document.write(" - "); document.write(x[i].lastChild.nodeValue); document.write("<br>"); }


Document 對象參考手冊 Document 對象