用Prototype触发事件 [英] Trigger an event with Prototype
问题描述
我使用观察方法绑定了一个事件监听器,但我也希望能够以程序方式启动该事件。
提前感谢
event.simulate。 js
适合您的需要。
我已经使用了这几次,它的作用就像一个魅力。它允许您手动触发本地事件,例如点击或悬停如下:
$( 富)模拟(点击)。
这个伟大的事情是,所有附加的事件处理程序仍然会被执行,就像你会已经单击了元素。
对于自定义事件,您可以使用标准原型方法 Event.fire()
。
Does anybody know of a method to trigger an event in Prototype, as you can with jQuery's trigger function?
I have bound an event listener using the observe method, but I would also like to be able to fire the event programatically.
Thanks in advance
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.
For custom events you can use the standard prototype method Event.fire()
.
这篇关于用Prototype触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!