e.which is not an event, which is a property of the event object, which most people label as e in their event handlers. It contains the key code of the key which was pressed to trigger the event (eg: keydown, keyup).

document.onkeypress = function(myEvent) { // doesn't have to be "e"
console.log(myEvent.which);
};

With that code, the console will print out the code of any key you press on the keyboard.

随机推荐

  1. JS实现上下左右对称的九九乘法表

    JS实现上下左右对称的九九乘法表 css样式 <style> table{ table-layout:fixed; border-collapse:collapse; } td{ padd ...

  2. python的加密算法(1):反转加密

    说白了,就是把字符串倒序. 在js里,有一个reverse.但是python中没有. 不过,有一个更简单的方法,就是: ‘abcd’ [::-1] 这里,具体解释一下: (参看:https://doc ...

  3. 前端工程师必备PS技能

    PS参考线及其辅助 视图-->新建参考线 也可以快捷键Ctrl+R,显示区的上侧和左侧就会出现标尺.任意点选中,并拖动标尺,便会出现浅蓝色的辅助线.只有在移动工具下,才能拖动某一条参考线. 删除 ...

  4. libev 学习使用

    libev 简单的I/O库.  a high performance full featured event loop written in c libev 的大小也比 libevent 小得多并且自 ...

  5. spring报错 :java.lang.NoSuchMethodException: <init>()

        Spring要求init-method是一个无参数的方法,如果init-method指定的方法中有参数,那么Spring将会抛出java.lang.NoSuchMethodException ...

  6. 【转.解析清晰】你真明白 Python 装饰器么?

      原文出处: 武沛齐    装饰器是程序开发中经常会用到的一个功能,用好了装饰器,开发效率如虎添翼,所以这也是Python面试中必问的问题,但对于好多小白来讲,这个功能 有点绕,自学时直接绕过去了, ...

  7. Wannafly挑战赛17 A 走格子【矩阵行走/模拟】

    [链接]:A [分析]:可以设置方向数组和标记数组.当不合法(越界/访问过)就转向,转向可以用now=(now+1)%4 [代码]: #include <bits/stdc++.h> #d ...

  8. hadoop学习二:hadoop基本架构与shell操作

    1.hadoop1.0与hadoop2.0的区别:

  9. 链表学习二:链表反转与查找倒数第K个

    //单链表反转 ListNode* RevertList(ListNode* m_pHead){ ListNode* pCurrent = m_pHead; ListNode* pPrev=NULL; ...

  10. decode and CASE

    CASE