问题描述
我注意到jQuery ready事件和函数在我的大多数javascript中仅使用了一次.但是,我在徘徊是否可以多次使用ready事件.例如,可以在我的主要html代码中的就绪事件函数调用中调用函数,然后再在我的.js文件中的另一个就绪事件函数调用内调用函数和事件吗?
I noticed that the jQuery ready event and function are used only once in most of my javascript. However, I was wandering if it is ok to use the ready event more than once. For example, is it ok to call functions in a ready event function call in my main html code, that then calls functions and events inside another ready event function call that is in my .js file?
推荐答案
是的,这是完全可以接受的:
Yes this is completely acceptable:
$(document).ready(function() {
// do this
}):
// some other js code
$(document).ready(function() {
// do something else
}):
在这种情况下,当dom准备就绪时,将执行两个内部的代码(或尽可能多的ready
).
In this case, when the dom is ready, code inside both (or as many ready
as you have) will be executed.
这篇关于页面或.js脚本中是否可以有多个jQuery ready事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!