哪个JQuery document.ready更好? [英] Which JQuery document.ready is better?

查看:93
本文介绍了哪个JQuery document.ready更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
jQuery $(function(){})和$(document).准备相同?

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

您知道哪个更好,为什么?

Do you know which one is better and why?

第一个;

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

第二个:

$(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 );
}

这篇关于哪个JQuery document.ready更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆