Clicking a link when enter key is pressed using jQuery

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

    I used the following with asp.net LinkButton

            $('#drivingSchoolInput').keypress(function (event) {
                if (event.keyCode == 13) {
                    eval($('#button1').attr('href'));
                }
            });
    

    I also had a FORM on the header with allowed for seaching, so I need to add another step to disable the FORM from posting.

            $('#drivingSchoolInput').keypress(function (event) {
                if (event.keyCode == 13) {
                    $('#header1_ButtonTerm').attr('disabled', 'disabled'); <-- hack added to kill FORM POST
                    eval($('#button1').attr('href'));
                }
            });
    

提交回复
热议问题