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

前端 未结 6 1973
深忆病人
深忆病人 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 12:59

    One way would be to remove all of the submit buttons and use input buttons to submit the form programatically. This would remove the ability to submit the form by hitting the enter key in a textbox. You could also leave one submit button as the default submit functionality, and use regular button inputs for the others and submit the form programatically.

    The obvious short-fall of this is that the users would require JavaScript to be enabled. If this isn't a problem this is a consideration for you.

    EDIT:

    Here, I tried to make an example for you using jQuery (the same functionality can easily be created without jQuery)... let me know if this helps...

    
    
    
        Untitled
        
        
    
    
        



提交回复
热议问题