本文介绍了甜蜜的警报继续确认提交表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$(。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(); }); });
更多推荐
甜蜜的警报继续确认提交表格
发布评论