How to prevent buttons from submitting forms

后端 未结 17 2142
礼貌的吻别
礼貌的吻别 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:29

    Just add e.preventDefault(); in your method should prevent your page from submitting forms.

    function myFunc(e){
           e.preventDefault();
    }
    

    According to the MDN Web Docs

    The preventDefault () method of the Event interface tells the user agent that if the event is not explicitly processed, its default action should not be taken into account as it would normally be. The event continues to propagate as usual, unless one of its listeners calls stopPropagation () or stopImmediatePropagation (), either of which terminates the propagation.

提交回复
热议问题