在多个js文件中具有多个$(document).ready函数的含义 [英] Implications of having multiple $(document).ready functions across multiple js files

查看:219
本文介绍了在多个js文件中具有多个$(document).ready函数的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

JQuery - multiple $(document).ready… ?

拥有多个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆