开发者

About jQuery .ready() function

In terms of execution time and resources employed, is it more convenient to load as much stuff as possible with 开发者_StackOverflow社区jQuery.ready() or the bare essentials?


just use it as trigger for you init functions... Don't put all your code in it:

don't do:

$(function(){
  var someFunction = function(){
   $("a").click(function(event){
     event.preventDefault();
   });
  };
  someFunction();
});

do:

var someFunction = function(){
   $("a").click(function(event){
     event.preventDefault();
   });
};
$(function(){
  someFunction();
});

its more readable, and it simply makes no sense to put all your code in the ready function.

ps:

$(function(){}) === $(document).ready()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜