$().ready()和$(document).ready()之间有区别吗 [英] Is there a difference between $().ready() and $(document).ready()

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

问题描述

我已经看到了一些他们可以做到的代码:

I've seen some code where they just do this:

$().ready(function()
{
    ...
});

这比做文档选择器要短,但是是同一回事吗?

This is shorter than doing a document selector but is it the same thing?

推荐答案

轻微更改:

$(document).ready(function() {});

等于:

$(function() {});

从jQuery 1.4开始:$().ready(function() { });在所有情况下均不能正确运行 .从发行说明中:

As of jQuery 1.4: $().ready(function() { }); no longer works correctly in all cases. From the release notes:

从jQuery 1.4开始,如果未将任何参数传递给jQuery()方法,则将返回一个空的jQuery集.在早期版本的jQuery中,将返回包含文档节点的集合.

As of jQuery 1.4, if you pass no arguments in to the jQuery() method, an empty jQuery set will be returned. In previous versions of jQuery, a set containing the document node would be returned.

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

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