向页面动态添加外部js

var script = document.createElement("script");
				
script.src = '/static/js/view/'+url+'.js';
var done = false;
script.onload = script.onreadystatechange = function() {
    if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
        done = true;
        script.onload = script.onreadystatechange = null;
        document.body.removeChild(script);
    }
};
document.body.appendChild(script);
posted @ 2016-04-22 11:31  陈朔  阅读(489)  评论(0编辑  收藏  举报