一 动态加载css
function loadCss(filename){
var headok =document.getElementsByTagName_r("head")[0];
css = document_createElement_x_x_x_x_x_x_x('link');
css.href =
"http://www2.fengwo.com/static/css/"+filename+".css";
css.rel = 'stylesheet';
css.type = 'text/css';
headok.a(css);
//注意document是没有Append方法的但又a方法jquery没有a方法
}
二 动态记载js和css 函数
var
$_JS_LOADED = [];
//已载入的文件
//动态加载js、css文件
function $import(type,src){
if(!$_JS_LOADED[src]){
if(type=="js"){
try{
var xhr = window.ActiveXObject ? new
ActiveXObject("Microsoft.XMLHTTP") : new
XMLHttpRequest();
xhr.open("GET", src, false);
xhr.send(null);
if(200 == xhr.status || 0 == xhr.status){
if (window.execScript)
window.execScript(xhr.responseText);
else window.eval.call(window, xhr.responseText);
}
$_JS_LOADED[src] = true;
}catch(e){
alert('系统错误: 加载文件"' + src + '"出错! \r\n[在第 ' + e.lineNumber + ' 行出现
' + e.message + ' 错误]');
}
}else if(type=="css"){
var css =
document_createElement_x_x_x_x_x_x("link");
css.setAttribute("rel", "stylesheet");
css.setAttribute("type", "text/css");
css.setAttribute("href", src);
if (typeof
css!="undefined"){
document.getElementsByTagName_r("head")[0].a(css);
$_JS_LOADED[src] = true;
}else{
alert('系统错误: 加载文件"' + src + '"出错!');
}
}
}
}
------------------调用方法------------------------------
<script
language="javascript">
$import("css","jpage/theme/default/css/jpage.css");
$import("js","jquery.js");
$import("js","cookie/jquery.cookie.js");//不用cookie,可以不加载,但需要将openCookies置为false
$import("js","jpage/jquery.jpage.js");
</script>
三 用过的动态加载css js javascript
方法
function loadCss(filename){
var headok
=document.getElementsByTagName_r("head")[0];
css =
document_createElement_x_x('link');
css.href =
"http://www2.livehow.com/static/theme/bluelife/css/"+filename+".css";
css.rel =
'stylesheet';
css.type =
'text/css';
headok.a(css);
}
function
loadJavaScript(filename){
var headjs
=document.getElementsByTagName_r("head")[0];
Jscript =
document_createElement_x_x('script');
Jscript.src =
"http://www2.livehow.com/static/theme/bluelife/js/"+filename+".js";
Jscript.type = 'text/javascript';
headjs.a(Jscript);
}
function
loadBdScript(filename){
var headjs
=document.getElementsByTagName_r("head")[0];
Jscript =
document_createElement_x_x('script');
Jscript.src =
"http://www2.livehow.com/static/js/ueditor/"+filename+".js";
Jscript.type = 'text/javascript';
headjs.a(Jscript);
}
加载中,请稍候......