【发布时间】:2017-05-29 14:10:19
【问题描述】:
我正在使用 goog.dom.safeHtmlToNode 动态更新带有内容的选项卡
因为新版本的 google 闭包库删除了 dom 片段方法:goog.dom.htmlToDocumentFragment(htmlString)。
消毒剂会从 dom 元素中删除我的“id=xyz”。例如:
'<input type="email" id="openid" name="openid" size="20" style="font-size: 18px" />'
变成
'<input type="email" size="20" style="font-size: 18px;" />'
我使用 id 从这些元素中获取用户输入的内容。 我如何告诉消毒剂不要删除这些属性?我尝试了以下代码但没有成功:
var sanitizer =
new goog.html.sanitizer.HtmlSanitizer.Builder()
.withCustomNetworkRequestUrlPolicy(goog.html.SafeUrl.sanitize)
.allowCssStyles()
.allowFormTag()
.addOriginalTagNames()
.allowDataAttributes([ "data-id","data-name" ]) //data-* attributes are inert as per HTML5 specs
.build();
goog.dom.safeHtmlToNode( sanitizer.sanitize (htmlString) );
我也尝试将我的“id”重命名为“data-id”,字符串仍然从净化的输出中删除。
Thank you in advance for your help on this matter.
【问题讨论】:
标签: javascript dom google-closure-library