Comment()

Experimental: 这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

构造函数 Comment() 创建一个 Comment 对象并返回,这个对象以可选的 DOMString 参数作为它的文本内容。

语法

comment1 = new Comment(); // Create an empty comment
comment2 = new Comment("This is a comment");

示例

var comment = new Comment("Test");

规范

Specification
DOM Standard
# ref-for-dom-comment-comment①

浏览器兼容性

BCD tables only load in the browser

备注: 对于不支持本构造函数的浏览器, Document.createComment() 或许可以使用。

相关文档