回车键的键值:13 Esc的键值:27 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <input type="text" id="username"/> <script type="text/javascript""> window.onload=function(){ document.getElementById("username").onkeydown=function(event){ if(event.keyCode===13){ alert('正在进行验证...') } } } </script> </body> </html>