最新消息:红方科技年末特惠:.com域名55元、云虚机五折优惠,买3年送2年,更有智能建站套餐等你来取!

JQuery 动态加载CSS与JS脚本文件

JS yinhexi 1283浏览 0评论

$.extend({
    includePath: '',
    include: function(file)
    {
        var files = typeof file == "string" ? [file] : file;
        for (var i = 0; i < files.length; i++)
        {
            var name = files[i].replace(/^\s|\s$/g, "");
            var att = name.split('.');
            var ext = att[att.length - 1].toLowerCase();
            var isCSS = ext == "css";
			var path = $.includePath + name;

            var head = document.getElementsByTagName('head')[0];
            if(isCSS){
				var link = document.createElement('link');
				link.href = path;
				link.rel = 'stylesheet';
				link.type = 'text/css';
				head.appendChild(link);
			}else{
				var script = document.createElement('script');
				script.src = path;
				script.type = 'text/javascript';
				head.appendChild(script);
			}
        }
    }
});
//$.include(['**.js','/css/pop_win.css']);

转载请注明:红方博客 » JQuery 动态加载CSS与JS脚本文件