用javaScript加载css、js


function addLink(url) {
  var link = document.createElement("link");
  link.rel = "stylesheet";
  link.type = "text/css";
  link.href = url;
  document.getElementsByTagName("head")[0].appendChild(link);
}


function addScript(url) {
  var newscript = document.createElement('script');
  newscript.setAttribute('type','text/javascript');
  newscript.setAttribute('src',url);
  var head = document.getElementsByTagName('head')[0];
  head.appendChild(newscript);
}

addScript("js文件链接");

addLink("css文件的链接");
Last modification:September 8, 2023
如果觉得我的文章对你有用,请随意赞赏