Different forms of $(document).ready

后端 未结 2 1853
忘了有多久
忘了有多久 2020-11-28 11:32

I have seen people writing

$(document).ready(function(){

});

and some writing

$(function() {

        });
2条回答
  •  难免孤独
    2020-11-28 12:22

    $ is the jQuery object itself, which when called implements a whole pile of different interfaces. $('string') runs a selector or constructs a node; $(domElement) wraps an element... and $(a_function) is a convenient short hand for $(document).ready(a_function). See the jQuery API docs for (much) more information.

    A note in passing: $(function () { ... }) is shorter, but if you ever want to search for all of your on-ready events, you might be wishing that you had .ready to search for :)

提交回复
热议问题