//加载css文件函数
function link(url) {
var link = document.createElement("link");
link.rel = "stylesheet";
link.type = "text/css";
link.href = url;
document.getElementsByTagName("head")[0].appendChild(link);
}
//加载css文件函数
//加载js文件函数
function script(url) {
var newscript = document.createElement('script');
newscript.setAttribute('type','text/javascript');
newscript.setAttribute('src',url);
var head = document.getElementsByTagName('head')[0];
head.appendChild(newscript);
}
//加载js文件函数
script("js文件链接");
//执行加载js文件
link("css文件的链接");
//执行加载css文件
利用JavaScript加载css、js文件
文章转载协议
转载需先申请授权,并保留授权码、原文地址和文中 go/affiliate 链接。
- 转载前需要申请授权
- 转载页需保留授权码、原文地址和文中 go/affiliate 链接
原文地址:https://www.geekcorelab.com/post/using-javascript-to-load-css-and-js-files