兼容firefox的 keyCode
<script language = "javascript"> document.onkeydown=inLogin function inLogin(e) { var e=window.event||e; var code = e.keyCode||e.which; if(code==13){ alert('你按了Enter键'); } } </script>
方法二:
<script type="text/javascript"> $(document).ready(function(){ $(document).keydown(function(){ var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异 if (event.keyCode == 13){ alert("你按了enter键"); } }); }); </script>
另附: 键盘按钮keyCode大全