页面 异步加载 js 文件 示例

    //loadjs 加载完数据再加载页面js
    var alldata;
    function loadJS( url, callback ){
        var script = document.createElement('script'),
            fn = callback || function(){};
        script.type = 'text/javascript';
        //IE
        if(script.readyState){
            script.onreadystatechange = function(){
                if( script.readyState == 'loaded' || script.readyState == 'complete' ){
                    script.onreadystatechange = null;
                    fn();
                }
            };
        }else{
            //其他浏览器
            script.onload = function(){
                fn();
            };
        }
        script.src = url;
        document.getElementsByTagName('head')[0].appendChild(script);
    }
    //加载数据
    $.getJSON("../api/alldata.json", function (data) {
        allData = data;
        loadJS('./assets/mobile_view_1.js',function(){
        });
        loadJS('./assets/mobile_view_2.js',function(){
        });
        loadJS('./assets/mobile_view_3.js',function(){
        });
    });