使用jquery动态加载js,css文件
view sourceprint?
01 $.extend({
02 includePath: '',
03 include: function(file) {
04 var files = typeof file == "string" ? [file]:file;
05 for (var i = 0; i < files.length; i++) {
06 var name = files[i].replace(/^\s|\s$/g, "");
07 var att = name.split('.');
08 var ext = att[att.length - 1].toLowerCase();
09 var isCSS = ext == "css";
10 var tag = isCSS ? "link" : "script";
11 var attr = isCSS ? " type='text/css' rel='stylesheet' " : " language='javascript' type='text/javascript' ";
12 var link = (isCSS ? "href" : "src") + "='" + $.includePath + name + "'";
13 if ($(tag + "[" + link + "]").length == 0) document.write("<" + tag + attr + link + "></" + tag + ">");
14 }
15 }
16 });
17
18 //使用方法
19 $.includePath = 'http://hi.baidu.com/javascript/';
20 $.include(['json2.js', 'jquery.tree.js', 'jquery.tree.css']);
使用jquery动态加载js,css文件
最新推荐文章于 2024-09-14 08:09:14 发布