码迷,mamicode.com
首页 > Web开发 > 详细

动态加载js和css

时间:2016-05-06 19:18:18      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:

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和css

标签:

原文地址:http://www.cnblogs.com/toward-the-sun/p/5466484.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!