JS 捕獲 input 中 鍵盤按鍵 的相應處理事件是很簡單的,google搜索一下很容易找到處理方式,請看如下一種簡單的處理方式:
HTML代碼:
<div> <input type="text" id="myinput" /> </div>
JavaScript 方法:
$("#myinput").on("keydown", function (e) { if (e.keyCode == 13) { //to-do when click Enter Key } });
下面列舉其他常用按鍵的所對應的KeyCode:
用Jquery綁定其他按鍵事件的方式,請看如下鏈接:http://api.jquery.com/category/events/keyboard-events/