火狐和IE都支持的回车事件代替按钮click事件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>火狐和IE都支持的enter事件</title>
<script src="http://blog.163.com/riwxf_520/blog/jquery-1.4.4.js" type="text/javascript" 
language="javascript"></script>
<script type="text/javascript">

function doSave(id) {
    document.onkeydown = function (e) {
      var theEvent = window.event || e;
      var code = theEvent.keyCode || theEvent.which;
      if (code == 13) {
          alert(id);// your button click function here
      }
    }
}

</script>
</head>
<body>
<form id="mainForm">
<input type="text" id="text1" onkeydown="javascript:doSave('text1');"/>
<input type="text" id="text2" onkeydown="javascript:doSave('text2');"/>
</form>

</body>
</html>

你可能感兴趣的:(click点击事件,enter回车事件)