Binding and triggering native and custom events in Prototype

*爱你&永不变心* 提交于 2019-12-13 00:47:52

问题


I'm having a bit of issue with events in prototype.

I'm trying to bind and fire the native events: onhashchange, and onpopstate. As well as my custom events: statechange and anchorchange. All these events are for the window element.

Here's the code I've already tried with no luck:

Element.observe(window,eventName,eventHandler);
Element.fire(window,eventName);

Any help would be appreciated.


回答1:


You can only use fire for custom events.

Take a look at this question/answer. I think it solves your problem. It's certainly what we use.




回答2:


I ended up coming up with this: https://gist.github.com/796871

Which allows a consistent API for custom and standard events.



来源:https://stackoverflow.com/questions/4806345/binding-and-triggering-native-and-custom-events-in-prototype

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