HTML DOM createComment() 方法

HTML DOM createComment() 方法

Document 对象参考手册 Document 对象

实例

可创建注释节点, 并插入HTML文档:


	var c=document.createComment("My personal comments");
document.body.appendChild(c);

输出结果:


<!--My personal comments-->

知识兔 »

定义和用法

createComment() 方法可创建注释节点。

浏览器支持

所有主要浏览器都支持 createComment() 方法

语法

document.createComment(text)

参数

参数类型 描述
textString可选. 添加的注释文本。

返回值

类型 描述
Comment object创建的注释节点

技术细节

DOM 版本Core Level 1 Document Object

Document 对象参考手册 Document 对象

计算机