异步加载javascript文件超时

时间:2015-02-15 05:11:09

标签: javascript timeout

我正在异步加载我的javascript文件。我需要确保满足加载顺序。这是我的加载功能:

    function addTag(name, attributes, cond) {
        var el = document.createElement(name),
            attrName;
        for (attrName in attributes) {
          el.setAttribute(attrName, attributes[attrName]);
        }
        if(cond != ''){
            el = document.createComment('[if '+cond+']>'+outerHTML(el) + '<![endif]');
        }
        var headEl = document.getElementsByTagName('head')[0];
        headEl.appendChild(el); 
    }

    function outerHTML(node){
        // if IE, Chrome take the internal method otherwise build one
        return node.outerHTML || (
            function(n){
                var div = document.createElement('div'), h;
                div.appendChild(n);
                h = div.innerHTML;
                div = null;
                return h;
            })(node);
    }

我当时认为应该调用超时函数,但我不太确定,也不太确定间隔时间。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

function callback(arg){
    //your stuffs
}
function main(arg, callback){
    //stuffs
    callback(arg);
}

希望这会有所帮助。对于more

相关问题