javascript拼接url自动引入js、css文件
javascript自动引入js、css文件
$(function () { var urls = ["CFDSpace/js/map/maptools.js", "CFDSpace/js/map/main.js"];//url数组 //拼接js url mapConfig.apiurl + "init.js", load(urls); }) function load(urls) {//url:需要加载js路径 //引入拼接css var esricss = mapConfig.apiurl + "esri/css/esri.css";//url是变量 document.write('<link href="' + esricss + '" rel="stylesheet" />'); //引入js for(let url of urls) { var script = document.createElement("script"); script.type = "text/javascript"; script.src = url; document.head.appendChild(script) } }