How to prevent buttons from submitting forms

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

    You can simply get the reference of your buttons using jQuery, and prevent its propagation like below:

     $(document).ready(function () {
        $('#BUTTON_ID').click(function(e) {
    
                e.preventDefault();
                e.stopPropagation();
                e.stopImmediatePropagation();
    
                return false;
        });});
    

提交回复
热议问题