html5添加输入框和按钮,如何在html5表单中的提交按钮中添加确认对话框?(How can I add confirmation dialog to a submit button in html...

在HTML5表单中添加确认对话框,可以使用表单的`onsubmit`属性或者按钮的`onclick`属性结合JavaScript的`confirm()`函数实现。当用户点击提交按钮时,会弹出一个确认对话框,询问用户是否真的要提交表单。如果用户点击确定,表单才会被提交;如果用户点击取消,表单提交则会被阻止。
摘要由CSDN通过智能技术生成

如何在html5表单中的提交按钮中添加确认对话框?(How can I add confirmation dialog to a submit button in html5 form?)

我在django创建了一个应用程序,我遇到了下一个问题:我在html中有一个带有提交按钮的表单,但我想在处理信息之前显示一个确认对话框以选择Yes或No 。 我怎么能这样做?

这是我的表单代码:

{% csrf_token %}

{{ form.as_p }}

非常感谢!

I am creating an application in django and I have the next problem: I have a form in html with a submit button, but I want to show a confirmation dialog to select Yes or No before processing the information. How could I do it?

This is my form code:

{% csrf_token %}

{{ form.as_p }}

Thank you so much!

原文:https://stackoverflow.com/questions/31963401

更新时间:2020-01-25 14:02

最满意答案

如果您只是想要用户确认,请在表单标记中使用onsubmit属性。

method="POST" action="/y/b/"

enctype="multipart/form-data"

οnsubmit="return confirm('Do you really want to submit the form?');"

>

type="submit" name="submit" value="A"

/>

编辑:或尝试下面的代码

method="POST" action="/y/b/"

enctype="multipart/form-data"

>

type="submit" name="submit" value="A"

οnclick="return confirm('Do you really want to submit the form?');"

/>

Have onsubmit attribute in your form tag like this if you just want a confirmation from user.

method="POST" action="/y/b/"

enctype="multipart/form-data"

οnsubmit="return confirm('Do you really want to submit the form?');"

>

type="submit" name="submit" value="A"

/>

EDIT: Or try below code

method="POST" action="/y/b/"

enctype="multipart/form-data"

>

type="submit" name="submit" value="A"

οnclick="return confirm('Do you really want to submit the form?');"

/>

相关问答

您在buttons对象中指定的函数是单击处理程序。 您可以通过该功能发送您的请求。 The function you specify in the buttons object is the click handler. You can send your request right in that function.

这个问题的接受的答案似乎是你正在寻找的。 简要摘要:在提交的事件处理程序中,调用event.preventDefault() 。 The accepted answer to this question appears to be what you're looking for. Short summary: in the event handler for the submit, call event.preventDefault().

return jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {

return r;

});

也许? jQuery需要你从.click函数返回“false”来停止默认操作,而现在你没有从该函数返回任何内容。 *编辑* 我只是看了jConfirm,并且因为它是如何工作的(特别是因为它没有返回任何东西;它只能通过它的回调返回值)它不可能以你想要的方式使用它。 你需要做的只是总是从你的onclick处理程序返

...

您的submit_form函数实际上并未尝试提交表单。 它目前在“Click Me”按钮上添加了一个点击事件,如果按下该按钮,则会提交您的表单。 如果要单击对话框的“是”按钮以提交表单,请尝试以下操作: function submit_form(){

$('#myForm').submit();

}

还要确保你的submi_form方法的名称只是一个拼写错误而不是你的实时代码...你错过了一个“t”。 Your submit_form function is not actually t

...

在对话框中执行.submit时,将再次执行提交代码。 尝试这个: $('#multi-dialog-confirm').dialog({

autoOpen: false,

height: 200,

modal: true,

resizable: false,

buttons: {

'Confirm': function(){

dialogueIsSubmitting = true;

$('#co

...

您可以在wp-admin/js/common.js中使用基本的客户端表单验证脚本,该脚本默认包含在所有管理页面中。 首先,通过在后期编辑屏幕上运行的插件添加操作: add_action('admin_print_scripts', 'my_validation_script');

function my_validation_script() {

global $post_type;

if(isset($post_type) && $post_type == 'knowledgeb

...

只需从button删除form属性button 。

...

我认为你的代码序列有问题,当函数$("#RedundantMessage2").dialog( ...... ); 执行不要等待用户响应在这种情况下“是”或“否”所以...你的标志redunt = "Active"没有意义。 buttons选项具有在选择opcion时执行的功能,因此您必须调用函数来执行post $(function () {

$('form').submit(function () {

$('#result').html(" ");

...

不要在表单中使用提交按钮,而是使用普通按钮,然后单击该按钮打开确认对话框。

您已经有了在对话框的提交按钮的onclick事件上触发表单提交的代码,所以现在只需删除表单提交上的处理程序。 Dont use submit button in your form, use a

...

如果您只是想要用户确认,请在表单标记中使用onsubmit属性。 https://jsfiddle.net/yetn60ja/

method="POST" action="/y/b/"

enctype="multipart/form-data"

οnsubmit="return confirm('Do you really want to submit the form?');"

>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值