在多个js文件中具有多个$(document).ready函数的含义 [英] Implications of having multiple $(document).ready functions across multiple js files
问题描述
拥有多个javascript文件有什么影响,每个文件都有自己的$(document).ready function?
What are the implications of having multiple javascript files, each with its own $(document).ready function?
推荐答案
当多个东西与 $(文档)绑定时.ready();
,事件将按照绑定的顺序命中。这没有真正的负面影响,但请记住,其中一种方法中定义的任何变量会失去范围,并且在其他事件中将无法使用。
When having multiple things bind with the $(document).ready();
, the events will be hit in the order that they were bound. There are no real negative repercussions with this, but keep in mind that any variables defined in one of these methods loses scope, and won't be available in the other events.
要解决javascript范围问题,只需在 $(document).ready();
块之外定义交叉就绪事件变量。
To get around the javascript scoping issues, just define cross-ready-event variables outside of the $(document).ready();
blocks.
这篇关于在多个js文件中具有多个$(document).ready函数的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!