动态加载js文件

    function loadScripts(array,callback){
        var loader = function(src,handler){
            var script = document.createElement("script");
            script.src = src;
            script.onload = script.onreadystatechange = function(){
                script.onreadystatechange = script.onload = null;
                handler();
            }
            var head = document.getElementsByTagName("head")[0];
            (head || document.body).appendChild( script );
        };
        (function run(){
            if(array.length!=0){
                loader(array.shift(), run);
            }else{
                callback && callback();
            }
        })();
    }

  

    loadScripts(['./static/autograph/libs/zlib/deflate.min.js',
      './static/autograph/libs/CryptoJS v3.1.2/components/core-min.js',
      './static/autograph/libs/CryptoJS v3.1.2/rollups/sha1.js',
      './static/autograph/libs/CryptoJS v3.1.2/rollups/tripledes.js',
      './static/autograph/libs/CryptoJS v3.1.2/components/mode-ecb.js',
      './static/autograph/libs/anysign_all.min.js',
      './static/autograph/libs/anysignCommentUI.js',
      './static/autograph/libs/jquery-1.4.2.min.js']);

  

猜你喜欢

转载自www.cnblogs.com/y896926473/p/9067828.html