Firefox中的事件全局对象 [英] Event global object in Firefox

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

问题描述

考虑以下代码:

<input id="myinput" type="text" size="40" onkeydown="myFunction()">

function myFunction() {
  console.log(event);
}

事件是一个全局对象,事件处理程序myFunction。但是,Firefox会引发错误:事件未定义,而Chrome和IE输出KeyboardEvent {...}。这是我遇到的最疯狂的事情之一。任何令人满意的解释?

event is a global object and is known inside the event handler myFunction. However, Firefox throws an error:event is not defined while Chrome and IE output KeyboardEvent {...}. This is one of the most crazy things I have met. Any satisfactory explanation?

推荐答案

Firefox的KeyboardEvent()期望事件传递给函数
尝试这个

Firefox's KeyboardEvent() expect event passed to the function Try this

<input id="myinput" type="text" size="40" onkeydown="myFunction(event)">

function myFunction(event){
    if(typeof event === 'undefined')
    {
        event = window.event;
    }

console.log(event);

}

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

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