💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# XML DOM - Comment 对象 ## 尝试一下 - 实例 下面的实例使用 XML 文件 [books.xml](images/books.xml)。 [外部 JavaScript](dom-loadxmldoc.html) 用于加载 XML 文件。 [createComment() - 创建一个注释节点](/try/try.php?filename=try_dom_createcomment) ``` <!DOCTYPE html> <html> <head> <script src="loadxmldoc.js"></script> </head> <body> <script> 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>"); } </script> </body> </html> ``` ## Comment 对象 Comment 对象表示文档中注释节点的内容。 ## Comment 对象属性 | 属性 | 描述 | | --- | --- | | [data](prop-comment-data.html) | 设置或返回此节点的文本。 | | [length](prop-comment-length.html) | 返回此节点的文本的长度。 | ## Comment 对象方法 | 方法 | 描述 | | --- | --- | | [appendData()](met-comment-appenddata.html) | 向节点追加数据。 | | [deleteData()](met-comment-deletedata.html) | 从节点删除数据。 | | [insertData()](met-comment-insertdata.html) | 向节点中插入数据。 | | [replaceData()](met-comment-replacedata.html) | 替换节点中的数据。 | | [substringData()](met-comment-substringdata.html) | 从节点中提取数据。 |