【问题标题】:Binding and triggering native and custom events in Prototype在 Prototype 中绑定和触发原生和自定义事件
【发布时间】:2011-01-26 15:28:40
【问题描述】:

原型中的事件有点问题。

我正在尝试绑定和触发本机事件:onhashchangeonpopstate。以及我的自定义事件:statechangeanchorchange。所有这些事件都针对window 元素。

这是我已经尝试过但没有成功的代码:

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

任何帮助将不胜感激。

【问题讨论】:

    标签: javascript event-handling prototypejs dom-events custom-events


    【解决方案1】:

    您只能对自定义事件使用火。

    Take a look at this question/answer. 我认为它可以解决您的问题。这当然是我们使用的。

    【讨论】:

    • 谢谢,我用它作为我回答的基础:)
    【解决方案2】:

    我最终想出了这个: https://gist.github.com/796871

    这允许为自定义和标准事件提供一致的 API。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-19
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      相关资源
      最近更新 更多