JS 捕获 input 中 键盘按键

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/ 

原文地址:https://www.cnblogs.com/mingmingruyuedlut/p/3181470.html