使用自定义模型弹出窗口确认表单提交 [英] Confirming a form submission with a custom model popup
问题描述
我的应用程序中有一些删除表单,我想在提交之前使用javascript/jQuery进行确认.
I have some delete forms in my app that I want to confirm with javascript/jQuery before submission.
简单的方法是这样做:
$('form.confirm-form').submit(function(){
return confirm('Are you sure?');
});
其中会弹出一个浏览器本地确认框,并且仅在用户单击确定"时提交表单.
Which brings up a borwser-native confirmation box and only submits the form if the user clicks OK.
对于更漂亮的东西,我认为我使用Bootstrap模式进行确认,并为此检查了 Bootbox.js库
For something prettier I thought I use a Bootstrap modal for the confirm and checked out the Bootbox.js library for this.
我似乎无法使其正常运行,因为它需要回调并且不会阻止表单提交.因此,我使用preventDefault
停止了过早提交表单,但现在
I can't seem to get it working properly as it requires a callback and does not prevent the form from submitting. So I use preventDefault
to stop the form submitting prematurely but now
- 我无法使用取消"按钮关闭模态,并且
- 确定"按钮无法提交表单.
这是我的代码:
$('form.confirm-form').submit(function(event) {
event.preventDefault();
bootbox.confirm("Are you sure?", function(result){
return result;
});
});
如何使用此库复制本机confirm
的行为?
How can I replicate the behaviour of the native confirm
with this library?
推荐答案
尝试以下
这篇关于使用自定义模型弹出窗口确认表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!