js文件引入其他js文件

栖桐

关注

阅读 56

2022-02-14

function loadJavaScript(url, success) {
    let domScript = document.createElement('script');
    domScript.src = url;
    success = success || function () {};
    domScript.onload = domScript.onreadystatechange = function () {
        if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
            success();
            this.onload = this.onreadystatechange = null;
            this.parentNode.removeChild(this);
        }
    }
    document.getElementsByTagName('head')[0].appendChild(domScript);
}

loadJavaScript('../../static/js/plugin/vue.js', function () {
    // do it!
})

精彩评论(0)

0 0 举报