$(document).ready() or $(function()) — Which to use?

后端 未结 4 535
后悔当初
后悔当初 2021-01-17 07:59

I saw there is an answered question about whether there is a difference between using $(document).ready(function(){}) and $(function(){}) (there is

4条回答
  •  生来不讨喜
    2021-01-17 08:30

    You can use either, $(function() {}) is just a shortcut that does exactly the same thing.

    Personally, I prefer $(function() { }) because...well, I type it a lot, and it's much quicker.

    I see a lot of questions of why $(document).load() doesn't work and such because they're not using the right event...I also think$(func) takes some ambiguity out, to me. Do whichever you prefer, what's clearer to you and your team is the best choice here.

提交回复
热议问题