event.which

event.which 1.1.3追加

戻り値:Number

キーボードまたはマウスイベント用です。押されたボタンに紐付けられたキーコードを取得することが出来ます。

デモ

押されたキーコードを表示します。

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="http://code.jquery.com/jquery-latest.js"></script>
  5. </head>
  6. <body>
  7. <input size="40" id="whichkey" value="キーボード入力してください">
  8. <div id="log"></div>
  9. <script>$('#whichkey').bind('keydown',function(e){
  10. $('#log').html(e.type + ': ' + e.which );
  11. }); </script>
  12. </body>
  13. </html>

押されたマウスボタンのコードを表示します。

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="http://code.jquery.com/jquery-latest.js"></script>
  5. </head>
  6. <body>
  7. <input size="40" id="whichkey" value="マウスボタンを押してください">
  8. <div id="log"></div>
  9. <script>
  10. $('#whichkey').bind('mousedown',function(e){
  11. $('#log').html(e.type + ': ' + e.which );
  12. });
  13. </script>
  14. </body>
  15. </html>

 Back to top

© 2010 - 2017 STUDIO KINGDOM