0
我們正在使用HtmlTextWriter動態地將腳本標記添加到頁面,這很好用。我們有一些需要添加異步關鍵字,我不知道如何去做。使用HtmlTextWriter將腳本標記添加到腳本標記
我希望標籤看起來像這樣。
<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'中,但是我看不到你需要它的地方。 –
我正在整合第三方應用程序,他們要求它完全像這樣在標記中。這是來自整合文件。 <!DOCTYPE HTML \t公共\t ... \t EN」 \t \t
\t \t啊,對不對在輸出中。據我所知,格式應該是'async =「async」'這基本上是writer.AddAttribute(「async」,「async」)。只要我可以告訴這將做你想要的(即輸出屬性沒有值。否則,你試過'writer.AddAttribute(「async」,string.Empty)''或'writer.AddAttribute(「async」,空)'? –