XML/HTML代码
- <p><input type="text" onkeydown="return enterSubmit(event)" /></p>
- <p><input type="button" value="提交" id="btn" onclick="login()" /></p>
JavaScript代码
- function enterSubmit(evt){
- evt = (evt) ? evt : ((window.event) ? window.event : "")
- var key = evt.keyCode?evt.keyCode:evt.which;
- if(key == 13){
- document.getElementById("btn").click();
- return false;
- }
- }
- function login(){
- alert("提交成功!");
- }