[javascript]

 

 
  1. function ready(fn){  
  2.     if(document.addEventListener){      //标准浏览器  
  3.         document.addEventListener('DOMContentLoaded',function(){  
  4.             //注销时间,避免反复触发  
  5.             document.removeEventListener('DOMContentLoaded',arguments.callee,false);  
  6.             fn();       //执行函数  
  7.         },false);  
  8.     }else if(document.attachEvent){     //IE浏览器  
  9.         document.attachEvent('onreadystatechange',function(){  
  10.             if(document.readyState=='complete'){  
  11.                 document.detachEvent('onreadystatechange',arguments.callee);  
  12.                 fn();       //函数执行  
  13.             }  
  14.         });  
  15.     }  
  16. }
posted on 2016-09-29 21:22  默默淡然  阅读(179)  评论(0编辑  收藏  举报