开发者

About jQuery .ready() function

开发者 https://www.devze.com 2023-03-10 19:30 出处:网络
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

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

精彩评论

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