页面动态加载js文件

function loadJS(url, onload) {
    var domscript = document.createElement('script');
    domscript.src = url;
    domscript.charset = 'utf-8';
    if (onload) {
        domscript.onloadDone = false;
        domscript.onload = onload;
        domscript.onreadystatechange = function () {
            if ("loaded" === domscript.readyState && domscript.onloadDone) {
                domscript.onloadDone = true;
                domscript.onload();
                domscript.removeNode(true);
            }
        };

  }
  document.getElementsByTagName('head')[0].appendChild(domscript);
}

  

posted @ 2015-04-28 14:51  人来人往  阅读(1049)  评论(0编辑  收藏  举报