zoukankan      html  css  js  c++  java
  • 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         }
  • 相关阅读:
    七牛云的 python sdk 是如何 批量删除资源的
    mysql 主从复制
    django3上线部署踩的坑
    基于linux在线预览
    数据库2
    数据库3
    安装 webstorm--->vue
    Django基础1
    pymysql基础
    前段之jQuery
  • 原文地址:https://www.cnblogs.com/aui-js/p/12144946.html
Copyright © 2011-2022 走看看