Js 动态插入css js文件

function loadjscssfile(filename,filetype){
    var file,    //动态插入的文件
        doc = document;
    if(filetype == "js"){
        file = doc.createElement('script');
        file.setAttribute("type","text/javascript");
        file.setAttribute("src",filename);
    }else if(filetype == "css"){
        file = doc.createElement('link');
        file.setAttribute("rel","stylesheet");
        file.setAttribute("type","text/css");
        file.setAttribute("href",filename);
    }
   if(typeof fileref != "undefined"){
        doc.getElementsByTagName("head")[0].appendChild(fileref);
    }
    
}
loadjscssfile("style.css","css");

loadjscssfile("main.js","js");

 

posted @ 2014-03-31 10:40  dtdxrk  阅读(598)  评论(0编辑  收藏  举报