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 |
浏览器兼容性
加载中…