jQuery newbie: what does jQuery(function($) { … }) means?

后端 未结 5 1530
旧时难觅i
旧时难觅i 2020-12-13 14:11

I know in jQuery, $(callback) is the same as jQuery(callback) which has the same effect as $(document).ready().

How about

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 14:52

    First off, jQuery() is not the same as $(document).ready()

    $() is a shortcut for jQuery()

    and...

    $(function(){ ...}); is a shortcut for $(document).ready(function(){ ... });

    Thus:

    jQuery(function(){ ... }) 
    

    Will function the same as

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

    But...

    jQuery('#foo').css("background-color", "#f00");
    

    would not function the same as

    $(document).ready('#foo').css("background-color", "#f00");
    

    So...

    jQuery() is not the same as $(document).ready()

提交回复
热议问题