文档:createComment() 方法
createComment() 创建一个新的注释节点,并返回该节点。
语法
js
createComment(data)
参数
data-
包含要添加到 Comment 中的数据的字符串。
返回值
一个新的 Comment 对象。
示例
js
const doc = new DOMParser().parseFromString("<xml></xml>", "application/xml");
const comment = doc.createComment(
"This is a not-so-secret comment in your document",
);
doc.querySelector("xml").appendChild(comment);
console.log(new XMLSerializer().serializeToString(doc));
// Displays: <xml><!--This is a not-so-secret comment in your document--></xml>
规范
| 规范 |
|---|
| DOM # ref-for-dom-document-createcomment① |
浏览器兼容性
加载中…