简体   繁体   中英

Make specific button clicked on enter key press

I have two buttons in my page.First one

<input id="btnSearch" type="button" onclick="searchClick();" value="" tabindex="2">

Second one

<input name="btnSignUp" id="btnSignUp" class="button03" type="submit" value="Bekræft">

As you can see both buttons are of type submit . When I press enter key always second one get clicked.I want to change it, I want the first button to be clicked always. Is there any way to achieve this, with out changing the attribute type of both buttons.

Try this, but first make sure to use different ids for the buttons...You can only use one id once.

   $(document).ready(function(){
        $('#formID').keypress(function(e){
          if(e.keyCode==13)
          $('#btnSignUp').click();
        });
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM