甜蜜的警报继续确认提交表格

编程入门 行业动态 更新时间:2024-10-28 20:22:14
本文介绍了甜蜜的警报继续确认提交表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

$(。swa-confirm)。on (submit,function(e){ e.preventDefault(); swal({ title:$(this).data(swa-title), text:$(this).data(swa-text),类型:warning, showCancelButton:true, confirmButtonColor:#cc3f44, confirmButtonText:$(this).data(swa-btn-txt), closeOnConfirm:false, html:false },function(){ } ); });

但点击确认后我希望它继续提交表单...

不好的想法会浮现在脑海中,例如:

var confirmed = false; (b)$($)$($)$($)$($。$)$($。 $ b e.preventDefault(); swal({ title:$(this).data(swa-title), text:$(this).data(swa ), type:warning, showCancelButton:true, confirmButtonColor:#cc3f44, confirmButtonText:$(this).data(swa- btn-txt), closeOnConfirm:true, html:false },function(){ confirm = true; $ this.submit(); }); } });

或将swa移动到按钮点击而不是提交,并在提交表单时使用。 p>

但我不喜欢这个解决方案,它看起来对我来说是frankesteini。当然还有更好的方法。

解决方案

$('#btn-submit')。 on('click',function(e){ e.preventDefault(); var form = $(this).parents('form'); swal({标题:你确定吗?,文本:你将无法恢复这个虚构的文件!,类型:警告, showCancelButton:true, confirmButtonColor:#DD6B55, confirmButtonText:是,删除它!, closeOnConfirm:false },函数(isConfirm){ if(isConfirm)form .submit(); }); });

I've this sweetalert triggered on submit of a form.

$(".swa-confirm").on("submit", function(e) { e.preventDefault(); swal({ title: $(this).data("swa-title"), text: $(this).data("swa-text"), type: "warning", showCancelButton: true, confirmButtonColor: "#cc3f44", confirmButtonText: $(this).data("swa-btn-txt"), closeOnConfirm: false, html: false }, function() { } ); });

but on clicking confirm I want it to continue submiting the form...

Bad ideas come to mind, like:

var confirmed = false; $(".swa-confirm").on("submit", function(e) { var $this = $(this); if (!confirmed) { e.preventDefault(); swal({ title: $(this).data("swa-title"), text: $(this).data("swa-text"), type: "warning", showCancelButton: true, confirmButtonColor: "#cc3f44", confirmButtonText: $(this).data("swa-btn-txt"), closeOnConfirm: true, html: false }, function() { confirmed = true; $this.submit(); }); } });

or moving swa to button click instead of on submit, and using on submit of a form.

but I don't like this solution, it looks frankesteini to me. Surely there is a better way

解决方案

$('#btn-submit').on('click',function(e){ e.preventDefault(); var form = $(this).parents('form'); swal({ title: "Are you sure?", text: "You will not be able to recover this imaginary file!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "Yes, delete it!", closeOnConfirm: false }, function(isConfirm){ if (isConfirm) form.submit(); }); });

更多推荐

甜蜜的警报继续确认提交表格

本文发布于:2023-11-27 17:07:08,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   表格   甜蜜

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!