[英]How to Load Js and CSS in an aspx page at a Certain Position.
我有一個Aspx頁面,它將在任何時間點動態使用10-15個用戶控件之間的任何位置。 所以我的要求是。每當使用特定的用戶控件時,我都需要在aspx頁面中使用一個占位符,在其中可以為該用戶控件加載css和js。 CSS和js映射將在用戶控件的頁面加載或preinit中可用。 知道如何實現嗎?
<%@ Register TagPrefix="usercontrol" TagName="test1" Src="~/path1.ascx" %>
<%@ Register TagPrefix="usercontrol" TagName="test2" Src="~/path2.ascx" %>
<head id="Head1" runat="server">
<meta http-equiv="X-UA-Compatible" content="IE=10" />
<meta name="Blah Blah" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Expires" content="0" />
.
.
.
.
.
**<Load Usercontrol1 css>
<Load Usercontrol2 css>**
</head>
<body>
Whole Aspx Control Body here..
**<Load Usercontrol1 js here>
<Load Usercontrol2 js here>**
</Body>
如果要在標記中添加css和js,則可以使用外部css和js文件以及require.js之類的框架(請參見http://requirejs.org/docs/start.html和CSS)來改進此功能
function loadCss(url) {
var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = url;
document.getElementsByTagName("head")[0].appendChild(link);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.