How to prevent buttons from submitting forms

后端 未结 17 2047
礼貌的吻别
礼貌的吻别 2020-11-21 04:43

In the following page, with Firefox the remove button submits the form, but the add button does not.

How do I prevent the remove button from submitting t

17条回答
  •  梦如初夏
    2020-11-21 05:28

    You're using an HTML5 button element. Remember the reason is this button has a default behavior of submit, as stated in the W3 specification as seen here: W3C HTML5 Button

    So you need to specify its type explicitly:

    
    

    in order to override the default submit type. I just want to point out the reason why this happens.

提交回复
热议问题