Event global object in Firefox [duplicate]

一个人想着一个人 提交于 2019-12-24 06:42:05

问题


Consider the following code:

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

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

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?


回答1:


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);

}


来源:https://stackoverflow.com/questions/37367752/event-global-object-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!