javascript 提交确认

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4571488/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 14:08:21  来源:igfitidea点击:

Confirmation on submit

javascriptalertconfirmation

提问by codedude

I have a form that submits information to a database. How can I make it so that when I click the submit button, I get an alert that asks me if I really want to submit it and when I click "Yes" it continues and if I click "no" it does not submit the information.

我有一个向数据库提交信息的表单。我怎样才能做到这一点,当我点击提交按钮时,我会收到一条警告,询问我是否真的想提交它,当我点击“是”时,它会继续,如果我点击“否”,它不会提交信息.

回答by BalusC

Use JavaScript confirm()function.

使用 JavaScriptconfirm()函数。

<input type="submit" onclick="return confirm('Are you sure?')">

If the user chooses Yes, it will return trueand the button's default action (submitting the form) will continue as usual. But if the user chooses No, it will return falseand the button's default action will be blocked.

如果用户选择Yes,它将返回true并且按钮的默认操作(提交表单)将照常继续。但是如果用户选择No,它将返回false并且按钮的默认操作将被阻止。