버튼 클릭 이벤트 대신 화호와 IE 모두 지원하는 리턴 이벤트

<!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>

좋은 웹페이지 즐겨찾기