TUTORIAL前端与浏览器FETCHED
HTML DOM createComment() 方法
HTML DOM createComment() 方法 Document 对象 实例 可创建注释节点, 并插入HTML文档: var c=document.createComment('My personal comments'); document.body.appendChild(c); 输出结果: <!--My personal comments--> 尝试一下 ..
更新于 2026/7/16
教程详情页默认 noindex。
HTML DOM createComment() 方法
实例
可创建注释节点, 并插入HTML文档:
var c=document.createComment("My personal comments");
document.body.appendChild(c);
document.body.appendChild(c);
输出结果:
<!--My personal comments-->
尝试一下 »
定义和用法
createComment() 方法可创建注释节点。
浏览器支持
![]()
![]()
![]()
![]()
![]()
所有主要浏览器都支持 createComment() 方法
语法
document.createComment(text)
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| text | String | 可选. 添加的注释文本。 |
返回值
| 类型 | 描述 |
|---|---|
| Comment object | 创建的注释节点 |
技术细节
| DOM 版本 | Core Level 1 Document Object |
|---|
Document 对象