Detect the Enter key in a text input field

后端 未结 10 724
粉色の甜心
粉色の甜心 2020-11-29 16:20

I\'m trying to do a function if enter is pressed while on specific input.

What I\'m I doing wrong?

$(document).keyup(function (e) {
    if ($(\".inpu         


        
10条回答
  •  天命终不由人
    2020-11-29 16:48

    The solution that work for me is the following

    $("#element").addEventListener("keyup", function(event) {
        if (event.key === "Enter") {
            // do something
        }
    });
    

提交回复
热议问题