本文介绍了如何以html5格式向提交按钮添加确认对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在 django
中创建一个应用程序,我有下一个问题:我在html中有一个带有提交按钮的表单,但我想显示一个确认对话框在处理信息之前,请选择是
或否
。我怎么能这样做?
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?
这是我的表格代码:
<form id="id" method="post" action="/y/b/" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<input class="btn btn-primary" type="submit" name="submit" value="A" />
</form>
非常感谢你!
推荐答案
如果您只是想要用户确认,请在表格标签中设置 onsubmit
属性。
Have onsubmit
attribute in your form tag like this if you just want a confirmation from user.
<form id="id"
method="POST" action="/y/b/"
enctype="multipart/form-data"
onsubmit="return confirm('Do you really want to submit the form?');"
>
<input class="btn btn-primary"
type="submit" name="submit" value="A"
/>
</form>
编辑或尝试以下代码
<form id="id"
method="POST" action="/y/b/"
enctype="multipart/form-data"
>
<input class="btn btn-primary"
type="submit" name="submit" value="A"
onclick="return confirm('Do you really want to submit the form?');"
/>
</form>
这篇关于如何以html5格式向提交按钮添加确认对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!