动态加载JS/CSS

一、动态加载JS

var head = document.getElementsByTagName('HEAD').item(0);
var script = document.createElement('script');
script.src = 'script.js';
script.type = 'text/javascript';
head.appendChild(script);

 

二、动态加载CSS

var head = document.getElementsByTagName('HEAD').item(0);
var style = document.createElement('link');
style.href = 'style.css';
style.rel = 'stylesheet';
style.type = 'text/css';
head.appendChild(style);

 

 

你可能感兴趣的:(JavaScript,css)