js 文件中,如何插入其它 js 、 css 文件

 1 /**
 2  *  实用jquery工具组件集合 v1.0
 3  *  Site:http://www.laosiv5.com
 4  *  By:老四
 5  *  QQ:252152780
 6  */
 7 
 8 // 一次单个js或者css
 9 function importDoc(path) 
10 {
11     var file = path; 
12     if (file.match(/.*\.js$/)){ //以任意开头但是以.js结尾正则表达式
13        document.write('<script type="text/javascript" src="' + file + '"></script>'); 
14     }
15     else if(file.match(/.*\.css$/)){
16        document.write('<link rel="stylesheet" href="'+file+'" type="text/css" />'); 
17     }
18 }
19 importDoc("style.css");
20 importDoc("script.js");
21 
22 // 一次引入多个js或者css
23 function importDocs(pathArray) //函数可以批量引入多个js、css
24 { 
25     for( var i=0; i < pathArray.length; i++ )
26     { 
27         var file = pathArray[i]; 
28         if (file.match(/.*\.js$/)){ 
29            document.write('<script type="text/javascript" src="' + file + '"></script>');
30         }
31         else if(file.match(/.*\.css$/)){
32            document.write('<link rel="stylesheet" href="'+file+'" type="text/css" />');
33         }
34     } 
35 }
36 var args = new Array("jquery.js","js2.js","css1.css");
37 importDocs(args);

 

posted @ 2015-10-09 23:47  勤奋的夕阳一刀  阅读(600)  评论(0编辑  收藏  举报