gpt4 book ai didi

javascript - HTML 中弹出消息的函数

转载 作者:行者123 更新时间:2023-11-28 00:51:01 24 4
gpt4 key购买 nike

我有 HTML 文件。无论用户在提交之前输入的详细信息是什么,我希望用户收到一条弹出消息,用户可以在其中查看他/她在表单中输入的所有详细信息。我想知道要使用什么功能,以便在提交表单之前会弹出一条消息进行确认。

最佳答案

如果您不太关心此弹出窗口的布局,只需使用window.confirm()

您可以将其构建到 HTML 表单中,如下所示:

<html>
<script>
function checkForm() {
var message = "You entered following data:\n" +
"Car name: " + document.getElementById('cn').value + "\n" +
"Car color: " + document.getElementById('cc').value + "\n" +
"Is this correct?";
if (window.confirm(message))
document.getElementById("carform").submit();
}

</script>


<form id="carform" target="...">
Car name: <input type="text" name="carname" id="cn"/><br/>
Car color: <input type="text" name="carcolor" id="cc"/><br/>
<input type="button" value="submit" onclick="checkForm()"/>
</form>

</html>

编辑要将输入的值与存储在 SQL 数据库中的值进行比较,您必须使用 PHP。你可以像这样实现它:

<html>
<script>
function checkForm() {
<?php
//Query the current databse values and store them for example in $carcolor $carname
echo 'var currentCarName = "' . $carname . '"';
echo 'var currentCarColor = "' . $carcolor . '"';

?>
var message = "You entered following data:\n" +
"Car name: " + document.getElementById('cn').value + "\n" +
" Old name: " + currentCarName + "\n" +
"Car color: " + document.getElementById('cc').value + "\n" +
" Old color: " + currentCarColor + "\n" +
"Is this correct?";
if (window.confirm(message))
document.getElementById("carform").submit();
}

</script>


<form id="carform" target="...">
Car name: <input type="text" name="carname" id="cn"/><br/>
Car color: <input type="text" name="carcolor" id="cc"/><br/>
<input type="button" value="submit" onclick="checkForm()"/>
</form>

</html>

关于javascript - HTML 中弹出消息的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26775654/

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