function loadjscssfile(filename,filetype){
if(filetype == "js"){
var fileref = document.createElement('script');
fileref.setAttribute("type","text/JavaScript");
fileref.setAttribute("src",filename);
}else if(filetype == "css"){

var fileref = document.createElement('link');
fileref.setAttribute("rel","stylesheet");
fileref.setAttribute("type","text/css");
fileref.setAttribute("href",filename);
}
if(typeof fileref != "undefined"){
document.getElementsByTagName("head")[0].appendChild(fileref);
}

}
loadjscssfile("do.js","js");
loadjscssfile("test.css","css");

代码整理自:http://www.cnblogs.com/lkf18/archive/2012/05/24/2515935.html

Related Posts: JavaScript动态加载JS与CSS文件 :