在firefox中'event'相当于' [英] 'event' equivalent in 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')
}
请注意,没有传递给该函数的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屋!