Use jquery to dynamically load js and css files
Copy codeThe Code is as follows: $. extend ({
IncludePath :'',
Include: function (file ){
Var files = typeof file = "string "? : 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) document. write ("<" + tag + attr + link + "> </" + tag + "> ");
}
}
});
// Usage
$. IncludePath = 'HTTP: // hi.baidu.com/javascript /';
$. Include (['json2. js', 'jquery. tree. js', 'jquery.tree.css ']);