What are the side effects (if any) of multiple $(document).ready() in an HTML page?

后端 未结 3 1343
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-20 15:04

I am using a web application framework (Symfony 1.3.6), which follows the MVC pattern.

The view layer is comprised of a template decorator. The template file may also in

3条回答
  •  梦谈多话
    2021-02-20 15:35

    You can indeed use as many instances of $(document).ready() on a page as you like. You can group your blocks of initialization code in whichever way makes the most sense for your application. What you gain in flexibility you may lose a bit in clarity, though, since it's no longer as easy to see what happens when onLoad fires.

    References: jQuery Tutorial on Multiple $(document).ready()

提交回复
热议问题