如何使用google
这样的完整处理程序编写动态MULTIPLE脚本加载器google.load("http://script1");
google.load("http://script2");
google.setOnLoadCallback(function(){});
感谢
答案 0 :(得分:1)
答案 1 :(得分:1)
答案 2 :(得分:0)
myApp.Loader = function(){
var queries = [];
var q = 0;
var p = 0;
var started = false;
var _callback = function(){};
var start = function(){
if(queries.length > 0 && !started){
started = true;
load(queries.shift());
} else if(queries.length > 0 && started){
load(queries.shift());
} else if(queries.length == 0 && started){
started = false;
if(q > 0 && q == p){
callback();
}
}
};
var load = function(fullUrl){
$.getScript(fullUrl, function() {
p++;
start();
});
};
var callback = function(){
_callback();
};
this.setCallback = function(fnc){
_callback = fnc;
if(q > 0 && q == p){
callback();
}
};
this.addQuery = function(query){
queries.push(query);
q++;
if(!started) {
start();
}
};
return this;
}
var Loader = new myApp.Loader();
myApp.load = function(fullUrl){
Loader.addQuery(fullUrl);
}
myApp.setOnLoadCallback = function(fnc){
Loader.setCallback(fnc);
}
并将其命名为
myApp.load("http://script1");
myApp.load("http://script2");
myApp.load("http://script3");
myApp.setOnLoadCallback(function(){
// complete script load handling
});