document.createComment()

本页内容

HTML DOM createComment() 方法

Document 对象

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


示例

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

    document.body.appendChild(c);

输出结果:


示例

<!--My personal comments-->

定义和用法

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

浏览器支持

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

语法

document.createComment(text)

参数

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

返回值

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

技术细节

DOM 版本 Core Level 1 Document Object

Document 对象

此页面最后编辑于2022年8月19日 (星期五) 11:20。