<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>键盘事件</title> <script src="js/jquery.js"></script> <script type="text/javascript"> var numrr=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"]; //页面加载完成简写形式 $(function(){ //keydown-按键按下 keyup-按键弹起 keypress-按下弹起整个过程 //用event.keyCode 获取按键的ascii代码 $("input").on("keydown",function(event){ console.info("触发keydown事件:"+event.keyCode); if(event.keyCode>=48&& event.keyCode<=57) { //0的ascii码是48 var r= numrr[event.keyCode-48]; $("#div1").text($("#div1").text()+r); return true;//返回true表示事件执行正常 } else { return false; //返回FALSE 本次事件被忽略 表示事件执行异常 } }); }) </script> </head> <body> <div> <div class="me">键盘测试案例 <input type="text" /><br> <div id="div1"></div> </div> </div> </body> </html>