用Prototype触发事件 [英] Trigger an event with Prototype

查看:157
本文介绍了用Prototype触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道在Prototype中触发一个事件的方法,你可以用jQuery的触发器函数?



我使用观察方法绑定了一个事件监听器,但我也希望能够以程序方式启动该事件。



提前感谢

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆