加载中...

event.which


概述

返回值:String

描述:针对键盘和鼠标事件,这个属性能确定你到底按的是哪个键。

event.whichevent.keyCodeevent.charCode 标准化了。推荐用 event.which 来监视键盘输入。更多细节请参阅: event.charCode on the MDN.

event.which也将正常化的按钮按下(mousedownmouseupevents),左键报告1,中间键报告2,右键报告3。使用event.which代替event.button

示例

实例

记录按键

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.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>

运行一下

实例

Log which mouse button was depressed.

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
 
<input id="whichkey" value="type something">
<div id="log"></div>
<script>
$('#whichkey').bind('mousedown',function(e){
  $('#log').html(e.type + ': ' +  e.which );
});
</script>
 
</body>
</html>

运行一下


还没有评论.