jQuery中的$(document).ready(…)和$(function(){})之间有什么区别? [英] What's the difference between $(document).ready(…) and $(function() {}) in jQuery?

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

问题描述

之间有什么区别

$(document).ready(function() {// Do something});

$(function() {//Do something});

在jQuery中?

推荐答案

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

等效.

实际上,无论包含什么对象,您都可以在任何 jQuery对象上调用.ready(handler),并且它将执行相同的操作:

Actually, you can call .ready(handler) on any jQuery object, no matter what it contains, and it will do the same thing:

ready: function( fn ) {
    // Attach the listeners
    jQuery.bindReady();

    // Add the callback
    readyList.add( fn );

    return this;
},

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

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