如何在html5表单中的提交按钮中添加确认对话框?
我在django
创建了一个应用程序,我遇到了下一个问题:我在html中有一个带有提交按钮的表单,但我想在处理信息之前显示一个确认对话框以选择Yes
或No
。 我怎么能这样做?
这是我的表单代码:
非常感谢!
请查看以下链接。
小提琴
function fnOpenNormalDialog() { $("#dialog-confirm").html("Confirm Dialog Box"); // Define the Dialog and its properties. $("#dialog-confirm").dialog({ resizable: false, modal: true, title: "Modal", height: 250, width: 400, buttons: { "Yes": function () { $(this).dialog('close'); callback(true); }, "No": function () { $(this).dialog('close'); callback(false); } } }); } $('#btnOpenDialog').click(fnOpenNormalDialog); function callback(value) { if (value) { alert("Confirmed"); } else { alert("Rejected"); } }
您可以安装JQuery插件或将自定义写入代码
安装JQuery插件jquery.confirm
试试这个:
并在您的按钮中添加id属性
注意 :最好在html head
标记内添加script
标记
在提交之前,您需要创建一个函数来检查用户是否要确认请求。 您可以使用preventDefault()的“confirm()”函数来停止提交,如果为true,则发送提交或将您的type = submit更改为按钮,并在函数中确认用户是否要继续发送请求。
在其onclick事件上添加一个javascript函数。 例如:
并添加javascript函数
function clicked() { if (confirm('Do you wanna to submit?')) { yourformelement.submit(); } else { return false; } }