简体   繁体   中英

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

I have a couple of user controls in an aspx page. And each user control may need to register a start-up block as an $(document).ready() function event handler.

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).

In JQuery event handlers are executed in the order they were bound.

Eventhandlers are not chained - as that would mean handler#3 would not fire if handler#2 failed to execute successfully. 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.

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他们按照他们注册的顺序被链接。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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