Four variations of jQuery ready() — what's the difference?

后端 未结 4 569
鱼传尺愫
鱼传尺愫 2020-12-09 12:41

I\'ve seen four different ways to tell jQuery to execute a function when the document is ready. Are these all equivalent?

$(document).ready(function () {
           


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-09 13:18

    There is no difference.

    $ is the same as jQuery. If you view the unminified source, you will see var $ = jQuery = ... or something to that effect.

    The jQuery function checks the type of it's parameter, if it is a function, it treats it the same as $(document).ready(...)

    Calling jQuery without a parameter defaults to using document. So $() and $(document) are identical. Try it in Firebug.

提交回复
热议问题