?
本文檔使用 php中文網(wǎng)手冊 發(fā)布
針對鍵盤和鼠標事件,這個屬性能確定你到底按的是哪個鍵或按鈕。
event.which 將 event.keyCode 和 event.charCode 標準化了。推薦用 event.which 來監(jiān)視鍵盤輸入。更多細節(jié)請參閱: event.charCode on the MDC.
記錄按鍵。
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-latest.min.js"></script> </head> <body> <input id="whichkey" value="type something"> <div id="log"></div> <script> $('#whichkey').bind('keydown',function(e){ $('#log').html(e.type + ': ' + e.which ); }); </script> </body> </html>