问题
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