如何在Javascript中触发个人事件 [英] How to Fire Personal Event in Javascript
问题描述
我不能在IE中使用Javascript来发起个人事件。在Firefox中工作很棒。
I can't fire personal events using Javascript in IE. In Firefox work great.
我的代码是:
var evento;
if(document.createEventObject)
{
evento = document.createEventObject();
document.fireEvent('eventoPersonal', evento);
}
//FF
else
{
evento = document.createEvent('Events');
evento.initEvent('eventoPersonal',true,false);
document.dispatchEvent(evento);
}
但是当试图执行 document.fireEvent('在IE中,eventoPersonal',evento);
,它不起作用。如何在IE中触发 NO自定义事件?
But when try to execute document.fireEvent('eventoPersonal', evento);
in IE, it doesn't work. How can I fire NO custom events in IE?
在Internet Explorer中,我收到错误:无效参数在执行<的行中code> document.fireEvent('eventoPersonal',evento);
In Internet Explorer I get the error: "Invalid arguments" in the line where execute document.fireEvent('eventoPersonal', evento);
推荐答案
你可以想考虑使用库来抽象它。两个原型jquery都会为你处理这个问题。 Jquery特别擅长于使用非常简单的代码创建事件。
You may want to consider using a library to abstract this. Both prototype an jquery will handle this for you. Jquery is especially good at allowing you to create an event with very simple code.
Jquery的文档可在此处获取:
http ://docs.jquery.com/Events
Jquery's documentation is available here: http://docs.jquery.com/Events
这篇关于如何在Javascript中触发个人事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!