【发布时间】:2014-01-09 20:04:32
【问题描述】:
我们正在使用 HtmlTextWriter 向页面动态添加脚本标签,效果很好。我们有一些需要添加 async 关键字,我不知道该怎么做。
我希望标签看起来像这样。
<script id="my_script" async type="text/javascript" src="myscript.js"></script>
我构建标签的方法如下所示。
internal static void RenderJavaScriptInclude(HtmlTextWriter writer, string filePath, string Id)
{
writer.AddAttribute(HtmlTextWriterAttribute.Id, Id);
writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript");
writer.AddAttribute(HtmlTextWriterAttribute.Src, filePath);
writer.RenderBeginTag(HtmlTextWriterTag.Script);
writer.RenderEndTag();
}
如何修改以添加“异步”?
非常感谢,
朗达
【问题讨论】:
-
异步需要什么?您可以将
async装饰器添加到RenderJavaScriptInclude但我看不到您需要它的位置。 -
我正在集成第三方应用程序,他们要求它完全像这样在标签中。这是来自集成文档。 EN"
YourWebsite.com ...您网站的标准文档正文... -
啊,就在输出中。据我所知,格式应该是
async="async",基本上是 writer.AddAttribute("async", "async")。据我所知,这会做你想做的(即输出没有值的属性。否则,你试过writer.AddAttribute("async", string.Empty)或writer.AddAttribute("async", null)吗?
标签: htmltextwriter