用于HTML中弹出消息的函数
Function for pop up message in HTML
我有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>
没有本地函数可以在加载HTML时显示弹出消息。然而,FancyBox正是这样做的。
http://fancybox.net/
查看这个问题和这个博客,了解有关如何进行的更多信息
相关文章:
- php函数向XMPP服务器发送消息,不提供日志;不起作用
- jQuery setTimeout ajax递归函数在即时消息程序中短时间后抛出错误
- 函数中输出错误的错误消息
- 错误消息:this.stopPropagation不是函数
- 为什么在定义回调/侦听器函数(异步消息传递,port.on)后没有立即设置全局变量
- 淘汰抛出消息:类型错误:
不是一个函数.什么意思 - 使用参数成功调用简单函数后出现意外警报,消息为“未定义”
- 触发警报消息时的调用函数
- 如何编写jQuery-AJAX函数来附加从PHP接收的列表项并显示“正在加载”.“消息,直到收到他的响应
- JAVASCRIPT --> 为什么我会收到错误消息“未捕获的类型错误:数字不是一个函数”
- JavaScript 和 if-else 函数的新手.(控制台日志中没有错误消息)
- CRM 2011 在线 - 保存或退出错误消息“<函数>匿名(容器,脚本内容,id)”
- 带有返回代码和返回消息的 PHP 函数,以供参考
- 为什么我的大多数 jquery 函数在将消息预置到现有消息列表后停止工作
- 用于HTML中弹出消息的函数
- 使用javascript中的postMessage函数将消息从一个域发送到另一个域
- 重定向后的Javascript函数回显消息
- 一个不需要输入错误消息的assert函数
- 当Ajax函数成功时显示消息
- JS消息'不是函数'CoffeeScript中