直接上代码
var importCssJs = {
css: function(path) {
if(!path || path.length === 0) {
throw new Error('参数"path"错误');
}
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.href = path;
link.rel = 'stylesheet';
link.type = 'text/css';
head.appendChild(link);
},
js: function(path) {
if(!path || path.length === 0) {
throw new Error('参数"path"错误');
}
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.src = path;
script.type = 'text/javascript';
head.appendChild(script);
}
}调用:
importCssJs.css('css/main.css');
importCssJs.js('js/main.js');
微信扫码查看本文
发表评论