为什么FF说window.event是不确定的? (带添加事件监听器的调用函数) [英] Why FF says that window.event is undefined? (call function with added event listener)
本文介绍了为什么FF说window.event是不确定的? (带添加事件监听器的调用函数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var ex = {
例子:function(){
var ref = window.event.target || window.event.srcElement; //这里
alert(ref.innerHTML); //例如
code $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ :
document.body.childNodes [0] .addEventListener('mouseover',ex.exampl,true);
只有Firefox说 window.event
isn 't定义...
我不知道该怎么做,才能使其工作。它在webkit浏览器和opera中运行得非常好(我无法在MSIE中检查它,我不关心它)。
为什么会发生这种情况?尝试使用传递的参数(在这种情况下命名为 e
)来获取事件)。我测试了这个,在chrome中支持 window.event
和 e
。
var ex = {
示例:function(e){
console.log(window.event);
console.log(e);
//检查是否有e或window.event并将它们用作evt
var evt = e || 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);
Only Firefox says that window.event
isn't defined...
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).
Why does it happen?
解决方案 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.
try checking for both, whichever exists
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
}
}
这篇关于为什么FF说window.event是不确定的? (带添加事件监听器的调用函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文