jquery enter key event submit (jquery 엔터키 이벤트)

by 조쉬 posted Nov 17, 2016
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

검색 페이지 작성시 엔터키로 submit 하는 방식입니다.


엔터의 key 코드는 13이기 때문에 key 코드 13인지 확인해서 submit 하면 됩니다.

<!doctype html>
<html lang="kr">
<head>
  <meta charset="utf-8">
  <title>demo</title>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  <script>
    $('form input').keydown(function(e) {
        if (e.keyCode == 13) {
            $('form').submit();
        }
    });
  </script>
</head>
<body>
    <form action="#">
       <input type="text" id="searchWord"/>
    </form>
</body>
</html>


Articles

1 2 3 4 5 6 7 8 9