My idea is to integrate these methods into $ when writing an independent module. in the tools object, next, on the page, call the Controller to load the module, and judge after loading. whether the number of objects in tools is equal to the number of modules loaded in a predefined definition. If the number of objects is not equal, the system waits for the objects. If the number is equal, the system executes the callback function.
Copy codeThe Code is as follows:
/*
* 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) {arglg = arglg-1; fn = arglast ;}
For (var I = 0; I <argleng; 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! ');
});