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 }