是$(function(){});和$(" document")。ready(function(){});相同? [英] Are $(function(){}); and $("document").ready(function(){}); the same?

查看:105
本文介绍了是$(function(){});和$(" document")。ready(function(){});相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直很喜欢Lynda.com的Jquery Essential Training,我注意到教练在开始时使用:

I've been enjoying Lynda.com's Jquery Essential Training, and I've noticed that in the beginning the instructor uses:

    Fig. 1

    $("document").ready(function(){
    fun stuff goes here
    });

然而,在他开始使用的某个地方:

However, somewhere along the line he starts using:

    Fig. 2

    $(function(){
    fun stuff goes here
    });

从他说话的方式来看,听起来好像是完全同义的(一些固有的jquery简写?)但据我所知,它从未被明确提及过。

From the way he speaks, it sounds as if they are completely synonymous (some inherent jquery shorthand?) but as far as I can tell, it's never explicitly touched upon.

我相信有人可以很快为我解决这个问题。我找到了这个但是我认为这个问题略有不同 - 我理解在文档就绪上调用函数的概念与全局可用函数的概念; (这些函数也有名字。)

I'm sure someone could clear this up quickly for me. I found this but I believe that question is slightly different--I understand the concept of calling a function on document ready versus one that is globally available; (those functions also have names.)

教师使用幻象函数(我认为这是一个没有名字的函数的术语),并在键入时输出图2 ,他说所以这将是文件准备......

The instructor uses phantom functions (I think that was the term for a function without a name,) and when typing out Fig. 2, he says "So this will be on document ready..."

推荐答案

是的,它们完全相同,只是别名。

Yes, they are exactly the same, just aliases.

来自jQuery网站


以下所有三种语法都是等价的:

All three of the following syntaxes are equivalent:

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


这篇关于是$(function(){});和$(" document")。ready(function(){});相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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