简体   繁体   中英

jQuery .on already fired event

If I do something like this after the DOM is loaded, the function still executes:

$(document).ready(fn)

However, the following does not execute the function if the 'myEvent' event has already been fired previously:

$(document).on('myEvent', fn)

Is there a jQuery solution , which does not require me to code my own event delegator, that fires previous events to a "late" event handler?

Actually I believe you don't need that because that should point to a bad design decision.

Furthermore, it's fine getting ready event callback executed even if the document has already signaled that it's ready , because this event happens once per page life-cycle .

Just imagine that click event would allow you to do that you're requesting for but before adding the event handler the user clicked the target element more than once? Would setting the event handler invoke it twice or more times?

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