jquery 动态记载css和js

 1 $.extend({
2 includePath: '',
3 include: function(file)
4 {
5 var files = typeof file == "string" ? [file] : file;
6 for (var i = 0; i < files.length; i++)
7 {
8 var name = files[i].replace(/^\s|\s$/g, "");
9 var att = name.split('.');
10 var ext = att[att.length - 1].toLowerCase();
11 var isCSS = ext == "css";
12 var tag = isCSS ? "link" : "script";
13 var attr = isCSS ? " type='text/css' rel='stylesheet' " : " language='javascript' type='text/javascript' ";
14 var link = (isCSS ? "href" : "src") + "='" + $.includePath + name + "'";
15 if ($(tag + "[" + link + "]").length == 0) $("head").append("<" + tag + attr + link + "></" + tag + ">");
16 }
17 }
18 });

使用方法

$.includePath = "http://localhost/";

$.include(['jquery.divbox.js','css/pop_win.css']);