$().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.