问题
I have a Prototype code that is triggered upon 'load' event:
Event.observe($(imageEl), 'load', this.someFunction.bind(this));
When I create 'Real' event using jQuery code like
jQuery(...imageEl selector...).attr("src", filename);
it fires the Prototype code (someFunction). Good!
Next I try to fire the Prototype code using jQuery trigger:
jQuery(...imageEl selector...).trigger('load');
But now, nothing happen i.e. this line doesn't fire the Prototype code.
Any idea how to trigger a Prototype event from jQuery?
回答1:
You should call your handler directly passing required arguments or trigger the native DOM event.
NOTE: prototype's fire and jquery's trigger create custom events, not native.
Read the following answers on how to trigger native events:
- trigger-an-event-with-prototype
- javascript-event-that-fires-without-user-interaction
来源:https://stackoverflow.com/questions/1331505/jquery-and-prototype-events