jquery: Choosing a document.ready method

后端 未结 2 1791
太阳男子
太阳男子 2021-01-21 01:48

I\'m new to jquery. I\'ve just read that these 2 are equivalent:

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

$(function() {});

Which one

2条回答
  •  猫巷女王i
    2021-01-21 02:08

    Feel free to use either one of them. Just as you think, the latter version is a shorthand for $(document).ready().

    The first option was available since the beginning of jQuery releases as oppose to the second option.

    Personally I prefer the second version for it is shorter.

提交回复
热议问题