$ ready

$(document).ready(function() {  

    //all your code goes here...  

});
ready: (function() {  
 
    ...  
 
    //Mozilla, Opera, and Webkit
    if (document.addEventListener) {
        document.addEventListener("DOMContentLoaded", idempotent_fn, false);
        ...
    }
    //IE event model
    else if (document.attachEvent) {  
 
        // ensure firing before onload; maybe late but safe also for iframes
        document.attachEvent("onreadystatechange", idempotent_fn);  
 
        // A fallback to window.onload, that will always work
        window.attachEvent("onload", idempotent_fn);  
 
        ...
    }  
 
})

网上看到的一段代码,查了一下zepto源码文档

 

ready: function(callback){
      if (readyRE.test(document.readyState)) callback($)
      else document.addEventListener('DOMContentLoaded', function(){ callback($) }, false)
      return this
 }

小demo:

 

var ee = {
  ready: function(callback){
    callback();
  }
};
    
ee.ready(function(){
  
  alert('bad');
  
});
posted @ 2012-12-26 10:20  jiangC  阅读(166)  评论(0编辑  收藏  举报