My idea is that when writing independent modules, pay attention to integrating these methods into the $.tools object. Next, in the page, call the controller to load the module, and judge the objects in $.tools after the loading is completed. Is the number equal to the predefined number of loaded modules? If not, continue to wait. If equal, execute the callback function.
/*
* LOADScript Mod
* Params url1,url2,url3,url4,fn
*/
jQuery.extend({
loadMod: function(){
var argleng = arguments.length,
arglast = arguments[argleng -1],
fn = false,
queue = [],
checknum = 0,
timer = null
// init
if(jQuery.isFunction( arglast)){argleng = argleng -1;fn=arglast;}
for (var i=0;i
queue.push(arguments[i]);
}
// getscript
jQuery.each(queue,function(i,o){
jQuery.getScript(o);
});
// check load ready?
loadReady();
function loadReady(){
if(jQuery.tools != undefined){
checknum = 0;
$.each(jQuery.tools ,function(i,n){
if(jQuery.isPlainObject(n)){checknum ;}
});
}
if(checknum != argleng){
clearTimeout( timer);
timer = setTimeout(loadReady, 100);
}else{
if(!!fn){fn.call(document.jQuery)}
}
}
}
});
// Usage
$.loadMod('a.js','b.js','c.js',function(){
alert('success!');
});