<script> window.onload=function(){ document.getElementById("enterSubmit").onkeyup=function(e){ e=e||window.event; //获取事件对象 var keycode= e.keyCode || e.which || e.charCode; //获取键码 if(keycode === 13){ //判断键码是否为13(回车键) alert("回车提交成功"); } } } </script> <body> <input type="text" id="enterSubmit" value="回车提交"/> </body>
来源:https://www.cnblogs.com/web-Knowledge/p/7070554.html