Should I use window.load or document.ready jquery

后端 未结 2 1353
梦毁少年i
梦毁少年i 2020-12-06 10:24

Recently I saw that you could use either

$(\'document\').ready(function() {
//Do Code
});

or

$(\'window\').load(function(         


        
2条回答
  •  心在旅途
    2020-12-06 11:10

    Well first of all you may want to consider using the "ready" event, which you can handler like this:

    $().ready(function() {
      ...
    });
    

    Or, more succinctly and idiomatically:

    $(function() {
      ...
    });
    

    The "load" handler really relates to an actual event, and can be handled on several different sorts of elements: and