溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Asp.net后臺(tái)怎么添加CSS、JS、Meta標(biāo)簽

發(fā)布時(shí)間:2021-08-07 22:06:21 來源:億速云 閱讀:110 作者:chen 欄目:開發(fā)技術(shù)

這篇文章主要講解了“Asp.net后臺(tái)怎么添加CSS、JS、Meta標(biāo)簽”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Asp.net后臺(tái)怎么添加CSS、JS、Meta標(biāo)簽”吧!

下面是從Asp.net 后臺(tái)添加CSS、JS、Meta標(biāo)簽的寫法,我們這里寫成函數(shù)方便以后使用。如果函數(shù)放在頁面類中, Page參數(shù)也可以不要。
首先導(dǎo)入命名空間 using System.Web.UI.HtmlControls;

復(fù)制代碼 代碼如下:


///
/// 添加JS腳本鏈接
///
/// 頁面
/// 路徑
public void AddJS(System.Web.UI.Page page, string url)
{
HtmlGenericControl jsControl = new HtmlGenericControl("script");
jsControl.Attributes.Add("type", "text/javascript");
jsControl.Attributes.Add("src", url);
page.Header.Controls.Add(jsControl);
}


///
/// 添加JS腳本內(nèi)容
///
/// 頁面
/// 腳本內(nèi)容
public void AddScript(System.Web.UI.Page page, string content)
{
HtmlGenericControl scriptControl = new HtmlGenericControl("script");
scriptControl.Attributes.Add("type", "text/javascript");
scriptControl.InnerHtml = content;
page.Header.Controls.Add(scriptControl);
}


///
/// 添加CSS樣式鏈接
///
/// 頁面
/// 路徑
public void AddCss(System.Web.UI.Page page, string url)
{
HtmlLink link = new HtmlLink();
link.Href = url;
link.Attributes.Add("rel", "stylesheet");
link.Attributes.Add("type", "text/css");
page.Header.Controls.Add(link);
}


///
/// 添加CSS樣式內(nèi)容
///
/// 頁面
/// 樣式內(nèi)容
public void AddStyle(System.Web.UI.Page page, string content)
{
HtmlGenericControl styleControl = new HtmlGenericControl("style");
styleControl.Attributes.Add("type", "text/css");
styleControl.InnerHtml = content;
page.Header.Controls.Add(styleControl);
}


///
/// 添加Meta標(biāo)簽
///
/// 頁面
/// Meta名字
/// Meta內(nèi)容
public void AddMeta(System.Web.UI.Page page, string name, string content)
{
HtmlMeta meta = new HtmlMeta();
meta.Name = name;
meta.Content = content;
page.Header.Controls.Add(meta);
}

感謝各位的閱讀,以上就是“Asp.net后臺(tái)怎么添加CSS、JS、Meta標(biāo)簽”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對Asp.net后臺(tái)怎么添加CSS、JS、Meta標(biāo)簽這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI