Sanitizer:setComments() 方法

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

Sanitizer 接口的 setComments() 方法用于设置清理器是否允许或移除注释。

此方法会设置此清理器配置中的 comments 属性。

语法

js
setComments(allow);

参数

allow

如果允许注释,则为 true;如果移除注释,则为 false

返回值

无 (undefined)。

示例

如何清理注释

下面的代码展示了 setComments() 方法的基本用法。

js
// Create sanitizer (in this case the default)
const sanitizer = new Sanitizer();

// Allow comments
sanitizer.setComments(true);

// Remove comments
sanitizer.setComments(false);

规范

规范
HTML Sanitizer API
# dom-sanitizer-setcomments

浏览器兼容性