且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HTML页面中多个$(document).ready()的副作用(如果有)是什么?

更新时间:2023-11-29 14:33:40

多个$(document).ready()调用没有问题,只有几个警告:

There are no problems with multiple $(document).ready() calls, only a couple of caveats:

  • 可读性降低.
  • 作用域:在一个$(document).ready()内部声明的函数/变量/对象在其他任何情况下均不可见.参见此简单的演示.
  • Reduced readability.
  • Scope: a function/variable/object declared inside one $(document).ready() will not be visible in any others. See this simple demo.

也请参见前面关于SO的问题:

Also see this previous question on SO: