© 本文档使用 php.cn手册 发布
针对键盘和鼠标事件,这个属性能确定你到底按的是哪个键或按钮。
event.which 将 event.keyCode 和 event.charCode 标准化了。推荐用 event.which 来监视键盘输入。更多细节请参阅: event.charCode on the MDC.
记录按键。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src=
"http://code.jquery.com/jquery-latest.min.js"
></script>
</head>
<body>
<input id="whichkey" value="type something">
<input id=
"whichkey"
value=
"type something"
>
<div id="log"></div>
<div id=
"log"
></div>
<script>
$('#whichkey').bind('keydown',function(e){
$(
'#whichkey'
).bind(
'keydown'
,
function
(e){
$('#log').html(e.type + ': ' + e.which ); });
'#log'
).html(e.type +
': '
+ e.which ); });
</script>
</body>
</html>