Use Javascript to change which submit is activated on enter key press

前端 未结 6 1979
深忆病人
深忆病人 2021-01-01 12:09

I have a form on an HTML page with multiple submit buttons that perform different actions. However, when the user is typing a value into a text input and hit enters, the bro

6条回答
  •  余生分开走
    2021-01-01 13:06

    Don't intercept the keydown event, intercept the submit event.

    so:

    form.onsubmit = function(e){
       // Do stuff.  Change the form's action or method maybe.  
       return true;
    }
    

提交回复
热议问题