| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2598 人关注过本帖
标题:这些什么意思
只看楼主 加入收藏
美食庄家267
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-3-11
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
这些什么意思
(function(global){
    function loadModule(){
        var LoadUtil = {};

        LoadUtil.loadJs = function(src) {
            document.write('<' + 'script language="javascript" type="text/javascript"');
            document.write(' src="' + src + '">');
            document.write('<'+'/script'+'>');
        };

        LoadUtil.loadAsyncJs = function(src, callback,rootObject){
            var se = document.createElement('script');
            se['type'] = "text/javascript";
            se['src'] = src;
            se['async'] = true;
            if(typeof callback == 'function'){
                // IE 下的 script 标签有 onreadystatechange 事件,无 onload 事件
                if (se['onreadystatechange']) {
                    se['onreadystatechange'] = function () {
                        if (this.readyState == "complete" || this.readyState == "loaded") {
                            callback();
                        }
                    };
                }else{
                    // W3C 标准的 script 标签没有 onreadystatechange 和 this.readyState
                    se['onload'] = function(){
                        callback();
                    }
                }
            }
            rootObject = rootObject || document.getElementsByTagName('head')[0];
            rootObject.appendChild(se);
        };

        //异步加载多个js, js串行处理
        LoadUtil.asyncSerialLoadResources = function (resources, callback,rootObject) {
            var totalCount = resources.length, curIndex = -1, self = this;
            var loadSingleFun;
            loadSingleFun = function () {
                curIndex++;
                if (curIndex >= totalCount) {
                    callback();
                } else {
                    var url = resources[curIndex];
                    if (url) {
                        self.loadAsyncJs(url, loadSingleFun,rootObject);
                    } else {
                        loadSingleFun();
                    }
                }
            };

            loadSingleFun();
        };

        //异步加载多个js, js串并行处理
        LoadUtil.asyncParallelLoadResources = function (resources, callback,rootObject) {
            var totalCount = resources.length;
            var finishCount = 0;
            for (var i=0; i<totalCount; i++) {
                self.loadAsyncJs(resources[i], function(){
                    if (++finishCount >= totalCount) {
                        callback();
                    }
                },rootObject);
            }
        };
        return LoadUtil;
    };


    if (typeof module != 'undefined' && module["exports"]) { // CommonJS
        module["exports"] = loadModule();
    } else if (typeof define != 'undefined' && define["amd"]) { // AMD
        define(loadModule);
    } else { // Shim
        global["LoadUtil"] = loadModule();
    }

})(this);
2016-03-11 15:21
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:20 
这段代码知识点很多,不知道楼主想问哪里

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2016-03-11 22:38
快速回复:这些什么意思
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024234 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved