if(document.addEventListener){ document.addEventListener("keypress",keyPressHandler, true); }else{ document.attachEvent("onkeypress",keyPressHandler); } function keyPressHandler(evt){ if(evt.keyCode == 13){ //为按下回车时调用的方法 SubmitLoginForm(); } }