jQuery监控键盘事件

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>event.which demo</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
<input id="whichkey" value="type something">
<div id="log"></div>
 
<script>
$( "#whichkey" ).on( "keydown", function( event ) {
$( "#log" ).html( event.type + ": " + event.which );
});
</script>
 
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>event.which demo</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
<input id="whichkey" value="click here">
<div id="log"></div>
 
<script>
$( "#whichkey" ).on( "mousedown", function( event ) {
$( "#log" ).html( event.type + ": " + event.which );
});
</script>
 
</body>
</html>

 

posted @ 2017-08-07 15:07  绝技小嗨皮  阅读(381)  评论(0编辑  收藏  举报
Title