动态创建JavaScript加载外面js文件

 

    function loadScript(url, callback) {
            var script = document.createElement('script');
            script.type = 'text/javascript';
            //  IE
            if (script.readyState) {
                script.onreadystatechang = function () {
                    if (script.readyState == 'complete' || script.readyState == 'loaded') {
                        callback();
                    }
                }
            } else {
                script.onload = function () {
                    callback();
                }
            }
            script.src = url;
            document.body.appendChild(script);
        }

 

你可能感兴趣的:(web前端)