Javascript - How to create a keypress event?

后端 未结 4 1278
误落风尘
误落风尘 2021-01-29 09:24

I\'ve looked on the internet for this and all I can find are depreciated functions so before posting please check to make sure that the code you suggest isn\'t depreciated.

4条回答
  •  面向向阳花
    2021-01-29 10:08

    $(document).ready(function () {
        var bool = false;
        $(document).keydown(function (e) {
            if (e.keyCode === 17) {
                bool = true;
            }
            if (bool == true && e.keyCode == 75) {
                alert("");
            }
        });
        $(document).keyup(function (e) {
            if (e.keyCode === 17) {
                bool = false;
            }
        });
    });
    

    This is how me and a friend got it working

提交回复
热议问题