Loading CSS and JS files using JavaScript

//加载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文件

Article repost policy

Request authorization before reposting and retain the authorization code, original URL, and go/affiliate links.

Original URL: https://www.geekcorelab.cn/en-US/post/using-javascript-to-load-css-and-js-files