다음 회차 키를 눌러 조회하다

9689 단어 조회

외부 js 파일enterKeySearch.js
var flag=false;

function search(submitButton){

        initSearch();

        window.onkeyup=function(event){

            if(flag&&event.keyCode==13){

                submitButton.submit();

            }

        } 

}

function initSearch(){

      var $querys = $(".query");

      for(var i=0;i<$querys.length;i++){

          var $query = $($querys.get(i));

          $query.bind({

             "focus":function(){

                 flag=true;

             },

             "blur":function(){

                 flag=false;

             }

          });

      }

}

사용 방식: 검색이 필요한 input 상자나 select에 스타일class="query"
search 방법을 호출하여 제출할form 폼의 jquery 대상을 전송합니다
다음은 데모:
<%@ page language="java" contentType="text/html; charset=utf-8"

    pageEncoding="utf-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

<link  type="text/css" href="../resources/css/bootstrap.css" rel="stylesheet"/>

<script type="text/javascript" src="../resources/js/jquery-1.11.2.js"></script>

<script type="text/javascript" src="../resources/js/bootstrap.js"></script>

<script type="text/javascript" src="../resources/js/enterKeySearch.js"></script>

</head>

<body>

<form id="search" action="${pageContext.request.contextPath }/keypress" method="post">

<table class="table">

    <tr>

        <td>

            

        </td>

        <td>

            <select name="level" class="query">

                <option value=""> </option>

                <option value="1"> ˜</option>

                <option value="2"> </option>

                <option value="3"> </option>

            </select>

        </td>

        <td>

             

        </td>

        <td>

            <input type="text" name="serialNo" class="query"/>

        </td>

    </tr>

    <tr>

        <td>‘ </td>

        <td>

            <input type="text" name="title" class="query"/>

        </td>

        <td> </td>

        <td>

            <input type="text" name="uploadTime" class="query"/>

        </td>

    </tr>

    <tr>

        <td colspan="4">

            <input class="btn btn-primary btn-sm query" type="button" value=" "/>

            <input class="btn btn-primary btn-sm"  type="button" onclick="" value=" "></a>

        </td>

    </tr>

</table>

</form>

<form action="">



</form>



</body>

<script type="text/javascript">

$(function(){

    var $submitButton = $("#search");

    search($submitButton);

});

</script>

</html>

좋은 웹페이지 즐겨찾기