js代碼中引入其他js文件


 1 /***引入 js 文件
 2            @example: import('js/aui.picker.js')
 3            @example: import(['js/aui.picker.js', 'css/aui.picker.css'])
 4         */
 5         function import(url){    
 6             var _this = this;
 7             switch (url.constructor){
 8                 case Array:
 9                     for(const [index, item] of url.entries()){
10                         creat(item);
11                     }
12                     break;
13                 case String:
14                     creat(url);
15                     break;
16                 default:
17                     break;
18             }
19             function creat(file){
20                 if(/^.+?\.js$/.test(file))
21                 { //JS文件引入
22                     var script = document.createElement("script");
23                     script.setAttribute("type", "text/javascript");
24                     script.setAttribute("src", file);
25                     document.querySelector('head').appendChild(script);
26                 }
27                 if(/^.+?\.css$/.test(file))
28                 { //CSS文件引入
29                     var css = document.createElement('link');
30                     css.rel = 'stylesheet';
31                     css.type = 'text/css';
32                     css.href = file;        
33                     document.querySelector('head').appendChild(css);    
34                 }            
35             }
36         }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM