开发者

Which JQuery document.ready is better? [duplicate]

开发者 https://www.devze.com 2023-03-13 03:38 出处:网络
This question already has answers here:开发者_C百科 Closed 10 years ago. Possible Duplicate: jQuery $( function() {} ) and $(document).ready the same?
This question already has answers here: 开发者_C百科 Closed 10 years ago.

Possible Duplicate:

jQuery $( function() {} ) and $(document).ready the same?

Do you know which one is better and why?

The first one;

$(document).ready(function() {
  // your code
});

The second One :

$(function() {
  // your code
});


It doesn't matter. I'm more of a fan of the 2nd case because its easier to type.

This is what the function does internally.

// HANDLE: $(function)
// Shortcut for document ready
} else if ( jQuery.isFunction( selector ) ) {
   return rootjQuery.ready( selector );
}


They are equivalent. It depends on how verbose or concise you want to be.


All three of the following syntaxes are equivalent:

 $(document).ready(handler)
 $().ready(handler) // (this is not recommended)
 $(handler)

http://api.jquery.com/ready/


Both are the same reference : http://api.jquery.com/ready/

0

精彩评论

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