如何控制先加载html再加载js

在公共 js 里加上这个方法:

/* bind event ro element (etype不含on)(bbind: true:bind;flase:unbind) */

/*这一段单独放在一个<script>标签里,最先加载,用来控制其他的加载*/

function bindEvent(obj,etype,lfun,bbind){

    if(bbind){
       if(window.attachEvent){
            obj.attachEvent("on"+etype,lfun);//IE浏览器
       }else{
           obj.addEventListener(etype,lfun,false); //火狐浏览器
       }
    }else{
       if(window.detachEvent){
           obj.detachEvent("on"+etype,lfun);
      }else{
          obj.removeEventListener(etype,lfun,false);
      }
   }
}
/**然后在逻辑处调用*/
bindEvent(window,"load",function(){
    /*这里写你加载完网页后要干的事情*/
 },true);
原文地址:https://www.cnblogs.com/bjxq-cs88/p/9007756.html