日期:2014-05-16  浏览次数:20612 次

动态加载javascript和css文件
在sencha touch中动态加载javascript和css文件:
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("css/app0050000007/BTravelMobile.css","css");
loadjscssfile("js/app0050000007/util.js","js");