在firefox中'event'相当于' [英] 'event' equivalent in firefox

查看:149
本文介绍了在firefox中'event'相当于'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码,它在Chrome中运行得非常好。

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

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

请注意,没有传递给该函数的event变量,但在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?

推荐答案

如果您使用onclick属性设置处理程序或某事(由于你标记了问题jQuery,你真的应该考虑不做),你必须明确地传递它:

If you're setting up the handler with an "onclick" attribute or something (which, since you tagged the question "jQuery", you really should consider not doing), you have to explicitly pass it:

<button type=button onclick='whatever(event)'>Click Me</button>

这篇关于在firefox中'event'相当于'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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