监听 keyup 事件时
$(document).on('keyup', on_key_up);
function on_key_up(event)
{
console.log('keycode:',event);
}
我记录这个:
altKey: false
bubbles: true
cancelable: true
char: undefined
charCode: 0
ctrlKey: false
currentTarget: document
data: undefined
delegateTarget: document
eventPhase: 3
handleObj: Object
isDefaultPrevented: function ot(){return!1}
jQuery19106670567644760013: true
key: undefined
keyCode: 69
metaKey: false
originalEvent: KeyboardEvent
relatedTarget: undefined
shiftKey: false
target: body
timeStamp: 1367933052234
type: "keyup"
view: Window
which: 69
您需要 keyCode(在本例中为 69)、shifKey、altKey、ctrlKey。例子:如果你按 shift+箭头向右,你会得到 keyCode:3, shiftKey:true。
function on_key_up(event)
{
if(event.shiftKey) // action
}
希望这可以帮助。