怎样肯定一个js 是不是加载完整或许页面中的一切js加载完整,而且使剧本的实行递次根据设定的递次实行?

//封装loadscript要领
export function loadScript(url, callback) {
    var script = document.createElement("script");
    script.type = "text/javascript"
    if (script.readyState) {
        script.onreadystatechange = function () {
            if (script.readyState == "loaded" || script.readyState == "complete") {
                script.onreadystatechange = null
                callback()
            }
        }
    } else {
        script.onload = function () {
            callback()
        }
    }
    script.src = url
    document.getElementsByName("head")[0].appendChild(script)
}
//嵌套运用
loadScript("file1.js", function () {
    loadScript("file2.js", function () {
        loadScript("file3.js", function () {
            alert("All files are loaded!")
        })
    })
})
    原文作者:htlshu
    原文地址: https://segmentfault.com/a/1190000017259745
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞