Clicking a link when enter key is pressed using jQuery

后端 未结 7 1886
无人及你
无人及你 2021-02-19 22:58

I\'m trying to make it so when a user is in a text box and they press enter, it is the same as clicking the link, in which case it should take them to another page. Here\'s what

7条回答
  •  暖寄归人
    2021-02-19 23:29

    I wanted to do something similar, so after reading David K Egghead's suggestion above I came up with this which triggers a "click" even on an anchor when enter is pressed. Could be used to "click" a button as well!

    $(document).keypress(function(event){if(event.keyCode==13){$('.save_icon').trigger("click");}});
    

提交回复
热议问题