简体   繁体   English

如果多个用户控件注册$(document).ready函数会发生什么?

[英]What happens if more than one user control registers $(document).ready function?

I have a couple of user controls in an aspx page. 我在aspx页面中有几个用户控件。 And each user control may need to register a start-up block as an $(document).ready() function event handler. 并且每个用户控件可能需要将启动块注册为$(document).ready()函数事件处理程序。

Do they override each previous functions of they are chained in order of registration? 他们是否覆盖了按照注册顺序链接的每个以前的功能?

They are just added as event handlers to the documents 'ready' event (an abstracted event provided by JQuery). 它们只是作为事件处理程序添加到文档的“ready”事件(JQuery提供的抽象事件)。

In JQuery event handlers are executed in the order they were bound. 在JQuery中,事件处理程序按它们绑定的顺序执行。

Eventhandlers are not chained - as that would mean handler#3 would not fire if handler#2 failed to execute successfully. 事件handler#3没有链接 - 因为这意味着如果handler#2未能成功执行,则handler#2 handler#3不会触发。 They are simply executed by the event manager in turn. 它们只是由事件管理器依次执行。

They will all be run in the order they were registered. 它们都将按照注册顺序运行。 See the fifth paragraph in the documentation to bind() , which .ready() , .load() etc. are shortcuts of. 请参阅文档中的第五段bind() ,其中.ready() .load()等是快捷方式。

When an event reaches an element, all handlers bound to that event type for the element are fired. 当事件到达元素时,将触发绑定到该元素的该事件类型的所有处理程序。 If there are multiple handlers registered, they will always execute in the order in which they were bound. 如果注册了多个处理程序,它们将始终按照绑定的顺序执行。 After all handlers have executed, the event continues along the normal event propagation path. 在执行所有处理程序之后,事件沿着正常事件传播路径继续。

jquery ready事件可以多次注册,并且它们是链接的

AFAIK他们按照他们注册的顺序被链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM