簡體   English   中英

在C#中使用RegisterClientScriptInclude時如何在腳本標記中添加屬性

[英]How do I add an attribute to the script tag when using RegisterClientScriptInclude in c#

我試圖像這樣使用時讓我的腳本標簽包含屬性defer="true"

string path = "~/scripts/v_wall.js";
Page.ClientScript.RegisterClientScriptInclude(typeof(SlideShow), "defaultslideshow", ResolveUrl(path));

如何讓這種方法像這樣渲染腳本標簽?

<script defer = "true" type="text/javascript">

     <!-- etc... -->

</script>

非常感謝!

為什么不使用方法RegisterClientScriptBlock代替呢? http://msdn.microsoft.com/zh-CN/library/btf44dc9.aspx

我想應該是這樣。

string scriptstr = "<script defer='true' type='' src=''></script>";
Page.ClientScript.RegisterClientScriptBlock(typeof(SlideShow), "defaultslideshow", scriptstr);

祝好運

我認為您將需要自己發出腳本標簽。 為了盡快將其添加到頁面中,以防頁面中的某些內容需要盡快使用javascript。

為此,您可以將它們添加到頁面標題中:

var sbText = new System.Text.StringBuilder(500);
// ToDo: Add your script to the textbuilder here
this.Page.Header.Controls.Add(New LiteralControl(sbText.ToString()));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM