Firefox 中的“事件"等价物 [英] 'event' equivalent in Firefox

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

问题描述

我正在使用以下代码,它在 Chrome 中运行良好.

I am using the following code and it works perfectly fine in Chrome.

function dayBind(xyzValue) {
    if(event.type == 'click')
       alert('Mouse Clicked')
}

请注意,没有传递给函数的事件"变量,但在 chrome 的情况下它仍然可供我使用.但是当我使用 Firefox 时,我得到了未定义的事件".我尝试使用以下解决方法:

Note that there was no 'event' variable passed to the function but still it was available for me in case of chrome. But when I use Firefox I get 'event' undefined. I tried using the following workarounds:

var e=arguments[0] || event;

还有:

var e=window.event || event;

但没有一个对我有用.Firefox 中是否有任何等效的事件"?

But none of them worked for me. Is there any 'event' equivalent in Firefox?

推荐答案

因为 IE 和 Chrome 把事件放在全局对象 window 中,所以你可以得到它.在firefox中,你需要让第一个参数是事件.

Because IE and Chrome put the event in the global object window, so you can get it. In firefox, you need to let the first parameter be the event.

function dayBind(event, xyzValue) {
    var e=event || window.event;
    if(event.type == 'click')
       alert('Mouse Clicked')
}

这篇关于Firefox 中的“事件"等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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