页面加载完时再动态添加脚步

//页面加载时不存在,加载完时再添加
function loadScript(url) {//外部文件
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = url;

    document.body.appendChild(script);
}

function loadScriptString(code) {//行内样式
    var script = document.createElement("script");
    script.type = "text/javascript";
    try {
        script.appendChild(document.createTextNode(code));
    } catch (ex) {
        script.text = code;
    }

    document.body.appendChild(script);
}

 

posted @ 2013-07-11 14:53  金帛  阅读(162)  评论(0编辑  收藏  举报