jQuery - Target button with enter key when input field is focused

后端 未结 5 1949
无人共我
无人共我 2021-02-01 04:33

I have an input field and a login button. I want to allow users to hit the \"enter\" key to click the button when the input field is focused. How would I do this with jQuery?<

5条回答
  •  故里飘歌
    2021-02-01 05:02

    You don't need jQuery for this, just change the button to type="submit":

    
    
    

    Then the

    will submit all by itself when you hit Enter inside the text input.

提交回复
热议问题