1// plugin author : chenjinfa@gmail.com
2// plugin name : $.include
3// $.include('file/ajaxa.js');$.include('file/ajaxa.css');
4// or $.includePath = 'file/';$.include(['ajaxa.js','ajaxa.css']);
5
6$.extend({
7 includePath: '',
8 include: function(file) {
9 var files = typeof file == "string" ? [file]:file;
10 for (var i = 0; i < files.length; i++) {
11 var name = files[i].replace(/^\s|\s$/g, "");
12 var att = name.split('.');
13 var ext = att[att.length – 1].toLowerCase();
14 var isCSS = ext == "css";
15 var tag = isCSS ? "link" : "script";
16 var attr = isCSS ? " type='text/css' rel='stylesheet' " : " language='JavaScript' type='text/JavaScript' ";
17 var link = (isCSS ? "href" : "src") + "='" + $.includePath + name + "'";
18 if ($(tag + "[" + link + "]").length == 0) document.write("<" + tag + attr + link + "></" + tag + ">");
19 }
20 }
21});
放在JavaScript文件头部,就像C#(using…)或Java(import …)