HTML DOM Document createComment() 方法
- Page précédente createAttribute()
- Page suivante createDocumentFragment()
- Retour en haut de page Documents du DOM Documents
定义和用法
createComment()
方法创建注释并返回注释节点。
实例
创建注释节点,并将其添加到文档中:
const comment = document.createComment("My comments"); document.body.appendChild(comment);
语法
document.createComment(data)
参数
参数 | 描述 |
---|---|
data | 可选。注释文本。 |
返回值
类型 | 描述 |
---|---|
节点 | 新创建的注释节点,文本为指定的 data。 |
浏览器支持
document.createComment()
是 DOM Level 1 (1998) 特性。
所有浏览器都支持它:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 9-11 | Support | Support | Support | Support |
- Page précédente createAttribute()
- Page suivante createDocumentFragment()
- Retour en haut de page Documents du DOM Documents