为什么 Firefox 说 window.event 是未定义的?(添加事件侦听器的调用函数) [英] Why Firefox says that window.event is undefined? (call function with added event listener)
本文介绍了为什么 Firefox 说 window.event 是未定义的?(添加事件侦听器的调用函数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这部分遇到了麻烦:
I have a trouble in this part:
var ex = {
exampl: function(){
var ref=window.event.target||window.event.srcElement; // here
alert(ref.innerHTML); // (example)
}
}
这个函数是这样调用的:
This function is called this way:
document.body.childNodes[0].addEventListener('mouseover',ex.exampl,true);
只有 Firefox 说 window.event
没有定义...
Only Firefox says that window.event
isn't defined...
我不知道该怎么做才能让它发挥作用.它在 webkit 浏览器和歌剧中运行良好(我无法在 MSIE 中检查它,我也不关心它).
I don't know what to do, to make it work. It works very well in webkit browsers and opera (I can't check it in MSIE and I don't care about it).
为什么会这样?
推荐答案
尝试使用传递的参数(在本例中名为 e
)获取事件.我对此进行了测试,Chrome 支持 window.event
和 e
.
try getting the event using the parameter passed (named e
in this case). i tested this and both window.event
and the e
is supported in chrome.
var ex = {
exampl: function(e){
console.log(window.event);
console.log(e);
//check if we have "e" or "window.event" and use them as "evt"
var evt = e || window.event
}
}
这篇关于为什么 Firefox 说 window.event 是未定义的?(添加事件侦听器的调用函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文