使用 Prototype 触发事件 [英] Trigger an event with Prototype
问题描述
有谁知道在 Prototype 中触发事件的方法,就像使用 jQuery 的触发函数一样?
Does anybody know of a method to trigger an event in Prototype, as you can with jQuery's trigger function?
我已经使用observe 方法绑定了一个事件侦听器,但我还希望能够以编程方式触发该事件.
I have bound an event listener using the observe method, but I would also like to be able to fire the event programatically.
提前致谢
推荐答案
event.simulate.js
满足您的需求.
event.simulate.js
fits your needs.
我已经多次使用它,它的作用就像一个魅力.它允许您手动触发原生事件,例如单击或悬停,如下所示:
I've used this several times and it works like a charm. It allows you to manually trigger native events, such as click or hover like so:
$('foo').simulate('click');
这样做的好处是所有附加的事件处理程序仍将被执行,就像您自己单击元素一样.
The great thing about this is that all attached event handlers will still be executed, just as if you would have clicked the element yourself.
对于自定义事件,您可以使用标准原型方法Event.fire()
.
For custom events you can use the standard prototype method Event.fire()
.
这篇关于使用 Prototype 触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!