Button with two event functions. How to stop the second during the first function?

亡梦爱人 提交于 2020-02-06 23:59:07

问题


I have a "delete" button and on clicking cancel on the confirm box, it still submits the form. What is the best way to stop the form submitting given that these two event functions apply to the same button?

The attribute data-confirm contains the confirm message.

$(document).on('click', "[data-confirm]", 
     (function () { return confirm($(this).attr('data-confirm')); }));
$(document).on("click", "input[type='submit'], button", buttonSubmit);

Here is the function buttonSubmit with custom code ommitted.

var buttonSubmit = (function (e)
{
    e.preventDefault();
    //...
    $(this).closest('form').submit();
});

Given a cancellation of confirm, how can i prevent buttonSubmit code from executing?


回答1:


You're looking for e.stopImmediatePropagation().



来源:https://stackoverflow.com/questions/10082508/button-with-two-event-functions-how-to-stop-the-second-during-the-first-functio

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!