How many times can I have jQuery's document ready function declared on a page?

后端 未结 3 1862
迷失自我
迷失自我 2021-02-05 08:42

How many times is it permitted to have the jQuery document ready function declared on a page, i.e.:

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

or

         


        
3条回答
  •  执念已碎
    2021-02-05 09:10

    One: There is no difference between the two.

    Quote:

    All three of the following syntaxes are equivalent:
    
    $(document).ready(handler)
    $().ready(handler) (this is not recommended)
    $(handler)
    

    Two: You can have as many of them as you wish, and they will be executed in the order that the $() or $(document).ready() functions are executed. (i.e. each handler is added to the queue)

提交回复
热议问题