使用jquery动态加载js,css文件
来源:互联网 发布:linux 命令结果 编辑:程序博客网 时间:2024/05/16 12:26
使用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']);