$(document).ready(function()和$(function())有什么区别? [英] What is the difference between $(document).ready(function() and $(function() ?

查看:100
本文介绍了$(document).ready(function()和$(function())有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我知道这是做什么的:

So I know what this does:

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

现在我看到有人这样做了:

Now I have seen people doing this lately:

<script type="text/javascript">     
$(function(){
    // Your code here...
});
</script>

这两种方式做同样的事情吗?

Are these two ways of doing the same thing?

我在这里看到一个匿名函数在jquery选择器中声明,但实际上从未被调用过,但是通过页面运行的方式,似乎这可能只是在pageload上运行。

I see an anonymous function being declared inside a jquery selector here, but never actually being invoked, yet by the way the page runs it seems that this may just run on pageload.

推荐答案

是的,他们正在做同样的事情。当调用的参数是单个函数时, $()函数包装 $(document).ready()对象。

yes, they're doing the same thing. the $() function wraps $(document).ready() when the parameter to the call is a single function object.

(编辑以反映评论中的问题)

(Edited to reflect a question in comment)

这篇关于$(document).ready(function()和$(function())有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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