Using jquery to dynamically load js files, jquery dynamically loads js files
The method is very simple. Here there is not much nonsense, and the code is provided directly:
Copy codeThe Code is as follows:
$. Extend ({
IncludePath :'',
Include: function (file ){
Var files = typeof file = "string "? [File]: file;
For (var I = 0; I <files. length; I ++ ){
Var name = files [I]. replace (/^ \ s | \ s $/g ,"");
Var att = name. split ('.');
Var ext = att [att. length-1]. toLowerCase ();
Var isCSS = ext = "css ";
Var tag = isCSS? "Link": "script ";
Var attr = isCSS? "Type = 'text/css 'rel = 'stylesheet'": "language = 'javascript 'Type = 'text/javascript '";
Var link = (isCSS? "Href": "src") + "= '" + $. includePath + name + "'";
If ($ (tag + "[" + link + "]"). length = 0) $ ("body "). append ("<" + tag + attr + link + "> </" + tag + "> ");
}
}
});
// Usage
$. Export depath = '../js/exam ';
$. Include (['/AddQuestion. js']);
If you have any questions, please leave a message below.