简体   繁体   English

javascript 中的键盘事件监听器

[英]keyboard EventListener in javascript

can anyone explain me how the argument e is captured and passed as a function callback which displays the keyboardEvent Object in console.谁能解释我如何捕获参数 e 并将其作为 function 回调传递,该回调在控制台中显示键盘事件 Object。 Same this can be acheived by using同样,这可以通过使用来实现

() => console.log(event);

so why do we do like this那么我们为什么要这样做

 (e) => console.log(e);
document.addEventListener("keydown", e => {
console.log("key Pressed");
console.log(e);
});

Event object exists in Spyglass based browsers but doesn't exist in Mosaic based browsers as a scriptable object, or at least as an accessible object.事件object存在于基于Spyglass的浏览器中,但不存在于基于Mosaic的浏览器中作为可编写脚本的 object,或者至少作为可访问的 object。

For this reason Mosaic (which was killed by The Project "Mosaic Killa"), from where we now have Mozilla for short, which in that process developed Netscape Navigator , had to arbitrarily pass the event object as a value of a function argument .出于这个原因, Mosaic (被“Mosaic Killa”项目杀死),从那里我们现在有Mozilla ,在这个过程中开发了Netscape Navigator ,必须任意传递事件 object作为 function参数

So, in order to be compatible with both worlds, the arbitrary event assignment to the first provided function argument has become mandatory for both.因此,为了与这两个世界兼容,对第一个提供的 function 参数的任意事件分配已成为两者的强制性。

Although you can still call for the event object in the Spyglass line of browsers, if that's your exclusive target clientele on some intranet app.尽管您仍然可以在Spyglass系列浏览器中调用事件 object,但如果这是您在某些 Intranet 应用程序上的专属目标客户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM