动态加载CSS和Javascript文件 javascript 和asp.net.
asp.net:
代码
HtmlGenericControl myHtmlJS = new HtmlGenericControl("script");
myHtmlJS.Attributes.Add("type","text/javascript");
myHtmlJS.Attributes.Add("src","javascript/Kathy.js");
Page.Header.Controls.Add(myHtmlJS);
HtmlLink myLink = new HtmlLink();
myLink.Attributes.Add("type","text/css");
myLink.Attributes.Add("href","css/Common.css");
myLink.Attributes.Add("rel","Stylesheet");
Page.Header.Controls.Add(myLink);
myHtmlJS.Attributes.Add("type","text/javascript");
myHtmlJS.Attributes.Add("src","javascript/Kathy.js");
Page.Header.Controls.Add(myHtmlJS);
HtmlLink myLink = new HtmlLink();
myLink.Attributes.Add("type","text/css");
myLink.Attributes.Add("href","css/Common.css");
myLink.Attributes.Add("rel","Stylesheet");
Page.Header.Controls.Add(myLink);
Javascript:
代码
function LoadJSFile(form_control_block, fileURL)
{
var head = document.getElementsByTagName("head")[0];
var djs_block = "djs_"+form_control_block;
var k_scrpt = document.getElementById(djs_block);
if(k_scrpt != null){
head.removeChild(k_scrpt);
}
k_scrpt = document.createElement("script");
k_scrpt.id = djs_block;
k_scrpt.language = "javascript";
k_scrpt.type = 'text/javascript';
k_scrpt.defer = true;
k_scrpt.src = fileURL;
head.appendChild(k_scrpt);
}
function LoadCSSFile(form_control_block, fileURL)
{
var head = document.getElementsByTagName("head")[0];
var dcss_block = "dcss_"+form_control_block;
var k_dcss = document.getElementById(dcss_block);
if(k_dcss != null){
head.removeChild(k_dcss);
}
k_dcss = document.createElement("link");
k_dcss.id = dcss_block;
k_dcss.rel = "stylesheet";
k_dcss.type = 'text/css';
k_dcss.href = fileURL;
head.appendChild(k_dcss);
}
{
var head = document.getElementsByTagName("head")[0];
var djs_block = "djs_"+form_control_block;
var k_scrpt = document.getElementById(djs_block);
if(k_scrpt != null){
head.removeChild(k_scrpt);
}
k_scrpt = document.createElement("script");
k_scrpt.id = djs_block;
k_scrpt.language = "javascript";
k_scrpt.type = 'text/javascript';
k_scrpt.defer = true;
k_scrpt.src = fileURL;
head.appendChild(k_scrpt);
}
function LoadCSSFile(form_control_block, fileURL)
{
var head = document.getElementsByTagName("head")[0];
var dcss_block = "dcss_"+form_control_block;
var k_dcss = document.getElementById(dcss_block);
if(k_dcss != null){
head.removeChild(k_dcss);
}
k_dcss = document.createElement("link");
k_dcss.id = dcss_block;
k_dcss.rel = "stylesheet";
k_dcss.type = 'text/css';
k_dcss.href = fileURL;
head.appendChild(k_dcss);
}
继续追寻。。。。。。