0
点赞
收藏
分享

微信扫一扫

js文件引入其他js文件

栖桐 2022-02-14 阅读 56
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 条评论