开发者

Is jQuery.ready useful on anything other than document?

I wa开发者_开发知识库s thinking about the jQuery $(document).ready event and it occurs to me that I've never seen anyone apply it on anything other than $(document). Is there any other legitimate use for it?


From the jQuery documentation:

The .ready() method can only be called on a jQuery object matching the current document, so the selector can be omitted.

They all do the same:

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

Source: http://api.jquery.com/ready/


No, jQuery .ready() "Specify a function to execute when the DOM is fully loaded", so it cannot be used on any other element


Well, basically, no. Whatever you put in there, it still gets called when the DOM loaded event is fired. For example, this:

$(undefined).ready(function() {
    alert("test");
});

Runs just like this:

$(document).ready(function() {
    alert("test");
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜