JS 前端动态引用 js 、 css 文件
JS 前端动态引用 js 、 css 文件
let jsArrPath = ['/web_config_other.js', '/web_point.js'] let cssArrPath = [] const head = document.getElementsByTagName("head")[0]; jsArrPath.forEach(jsPath => { let scriptElement = document.createElement("script"); scriptElement.type = "text/javascript"; scriptElement.src = jsPath; scriptElement.async = false; head.appendChild(scriptElement); }) cssArrPath.forEach(cssPath => { let linkElement = document.createElement("link"); linkElement.setAttribute("rel", "stylesheet"); linkElement.setAttribute("type", "text/css"); linkElement.setAttribute("href", cssPath); head.appendChild(linkElement); });
end