gpt4 book ai didi

php - 表单提交前确认

转载 作者:IT王子 更新时间:2023-10-29 00:04:52 24 4
gpt4 key购买 nike

我已经搜索过答案,但找不到!

我有一个简单的表格,

<form action="adminprocess.php" method="POST">
<input type="submit" name="completeYes" value="Complete Transaction" />
</form>

在处理表单之前,我如何调整它以确认?

我尝试了 onclick,但无法正常工作。

有什么想法吗?

更新 - 我现在拥有的。

<script type="text/javascript">
var el = document.getElementById('myCoolForm');

el.addEventListener('submit', function(){
return confirm('Are you sure you want to submit this form?');
}, false);
</script>

<form action="adminprocess.php" method="POST" id="myCoolForm">
<input type="submit" name="completeYes" value="Complete Transaction" />
</form>

最佳答案

HTML:

<form action="adminprocess.php" method="POST" id="myCoolForm">
<input type="submit" name="completeYes" value="Complete Transaction" />
</form>

JavaScript:

var el = document.getElementById('myCoolForm');

el.addEventListener('submit', function(){
return confirm('Are you sure you want to submit this form?');
}, false);

编辑:你总是可以像这样使用内联 JS 代码:

<form action="adminprocess.php" method="POST" onsubmit="return confirm('Are you sure you want to submit this form?');">
<input type="submit" name="completeYes" value="Complete Transaction" />
</form>

关于php - 表单提交前确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6493009/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com