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



posted @   无心々菜  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
点击右上角即可分享
微信分享提示