好好爱自己!

e.which

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.

posted @ 2018-06-13 16:29  立志做一个好的程序员  阅读(185)  评论(0编辑  收藏  举报

不断学习创作,与自己快乐相处