jsLoader、cssLoader、imageLoader

时间:2023-03-09 05:13:55
jsLoader、cssLoader、imageLoader
	//js文件加载
function jsLoader(url,callback){
var script = document.createElement("script");
script.src = url;
script.type = 'text/javascript';
script.language = 'javascript';
script.onload = script.onreadstatechange = function(){
isFunction(callback)&&callback();
};
document.getElementsByTagName("body")[0].appendChild(script);
} //css文件加载
function cssLoader(url,callback){
var link = document.createElement("link");
link.rel="stylesheet";
link.type="text/css";
link.href=url;
link.onload = link.onreadstatechange = function(){
isFunction(callback)&&callback();
};
document.getElementsByTagName("head")[0].appendChild(link);
} //图片文件加载
function imageLoader(url,targetId,callback){
var img = document.createElement("img");
img.src=url;
img.onload = link.onreadstatechange = function(){
isFunction(callback)&&callback();
};
document.getElementById(targetId).appendChild(link);
} function isFunction(obj){
return Object.prototype.toString.call(obj)==="[object Function]";
}