带有两个事件功能的按钮。如何在第一个功能期间停止第二个? [英] Button with two event functions. How to stop the second during the first function?

查看:97
本文介绍了带有两个事件功能的按钮。如何在第一个功能期间停止第二个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个删除按钮,点击确认框上的取消,它仍然提交表格。
$ b

属性data-confirm包含确认消息,停止表单提交的最佳方法是什么?

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

以下是使用自定义代码的函数 buttonSubmit

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

如果取消确认,我该如何防止 buttonSubmit code from execution?

解决方案

您正在寻找 e.stopImmediatePropagation()


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?

解决方案

You're looking for e.stopImmediatePropagation().

这篇关于带有两个事件功能的按钮。如何在第一个功能期间停止第二个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆