jQuery and Prototype events

本秂侑毒 提交于 2019-12-02 01:43:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!