Clicking a link when enter key is pressed using jQuery

后端 未结 7 1928
无人及你
无人及你 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:36

    Check this out: jQuery Event Keypress: Which key was pressed?

    I'll just consolidate the codes from that post here:

    $('#searchbox input').bind('keypress', function(e) {
     var code = e.keyCode || e.which;
     if(code == 13) { //Enter keycode
       //Do your stuff + form submit
     }
    });
    

    PS: I have never tested it, but it 'should' work. :P

提交回复
热议问题