Dynamic Loading of js Based on prototype. js
Usage:
1. Introduce prototype Library
<Script type = "text/javascript" src = "/js/prototype. js"> </script>
2. Introduce webJsBase. js
<Script type = "text/javascript" src = "/js/webJsBase. js? Load = ad, adTopDown, logoTip, iBanner "> </script>
Note: ad, adTopDown, logoTip, and iBanner are dynamically introduced js files. For example, ad. js
Below is the code
/*
Dynamic Loading of js v1.0 by: dum 2012-03-08 renwumao.com
Usage: src = "webJsBase. js? Load = a, B"
Note: load the js files in the current directory.
*/
Var webJsBase = {
Require: function (libraryName ){
Document. write ('<script type = "text/javascript" src = "' + libraryName + '"> <\/script> ');
},
Load: function (defaultLoad ){
If (typeof Prototype = 'undefined') | (typeof Element. Methods = 'undefined '))
Throw ('prototype lib loading failed! ');
If (typeof defaultLoad = 'undefined') defaultLoad = '';
Var js =/webJsBase \. js (\?. *)? $ /;
$ ('Head script [src] '). findAll (function (s ){
Return s. src. match (js );
}). Each (function (s ){
Var path = s. src. replace (js ,'');
Var primary des = s. src. match (/\?. * Load = ([a-zA-Z0-9 _,] *)/);
(Des? Des [1]: defaultLoad). split (','). each (function (include ){
WebJsBase. require (path + include + '. js ');
});
});
}
};
WebJsBase. load ();
From renwumao.com (Task cat)