JQuery:拦截点击提交按钮

JQuery: intercept click submit button

我有这段代码可以拦截提交按钮的点击,但根本不起作用

JS

$('#deleteDescriptionButtonId3').click(function () {
    alert('deleting description...');

    $('#productFormId').attr('method', 'post');
    $('#productFormId').attr('action', '/nicinc/desc/del/3');
}); 

HTML

<textarea id="descriptions0.text" name="descriptions[0].text" class="form-control" rows="4"> 
    ASDADS
</textarea>
<span class="clear space10">&nbsp;</span>
<button id="deleteDescriptionButtonId3" class="btn btn-primary" type="submit">
    Delete description
</button>

尝试将 type="submit" 更改为 type="button"

您可以使用event.preventDefault();

这是一个例子

$( "#deleteDescriptionButtonId3" ).click(function( event ) {
  event.preventDefault();

  alert('deleting description...');

    $('#productFormId').attr('method', 'post');
    $('#productFormId').attr('action', '/nicinc/desc/del/3');
    $('#form_id').submit();
});

这里#form_id 是您要提交的表单