JS动态加载js/css文件

2017-01-18  本文已影响134人  jesn

 var dynamicLoading = {

css: function (path) {

if (!path || path.length === 0) {

throw new Error('argument "path" is required !');

}

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('argument "path" is required !');

}

var head = document.getElementsByTagName('head')[0];

var script = document.createElement('script');

script.src = path;

script.type = 'text/javascript';

head.appendChild(script);

}

}

//动态加载 JS 文件

dynamicLoading.css("skin/css/2017NewYear/xinnian.css");

上一篇下一篇

猜你喜欢

热点阅读