gpt4 book ai didi

javascript - 表单弹出框错误

转载 作者:行者123 更新时间:2023-12-03 02:10:33 24 4
gpt4 key购买 nike

我有一个 PHP 表单,其操作链接是另一个 PHP 页面,它将用户输入的数据添加到数据库中,然后将它们重定向到另一个页面。

我试图在将 PHP 表单发送到其操作页面之前显示一个弹出窗口。我面临的问题是,每当我按下提交/创建按钮时,弹出窗口都会出现一秒钟,然后自动消失。

通过故障排除,我发现问题出现在表单标记内,因为当按钮脱离表单时它执行得很好。

我的代码:

<?php
session_start();
?>


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
#dialogoverlay{
display: none;
opacity: .8;
position: fixed;
top: 0px;
left: 0px;
background: #FFF;
width: 100%;
z-index: 10;
}
#dialogbox{
display: none;
position: fixed;
background: #000;
border-radius:7px;
width:550px;
z-index: 10;
}
#dialogbox > div{ background:#FFF; margin:8px; }
#dialogbox > div > #dialogboxhead{ background: #666; font-size:19px;
padding:10px; color:#CCC; }
#dialogbox > div > #dialogboxbody{ background:#333; padding:20px;
color:#FFF; }
#dialogbox > div > #dialogboxfoot{ }
#dialogbox > div > #dialogboxfoot2{ }
</style>
<script>
function CustomAlert(){
this.render = function(dialog){
var winW = window.innerWidth;
var winH = window.innerHeight;
var dialogoverlay = document.getElementById('dialogoverlay');
var dialogbox = document.getElementById('dialogbox');
dialogoverlay.style.display = "block";
dialogoverlay.style.height = winH+"px";
dialogbox.style.left = (winW/2) - (550 * .5)+"px";
dialogbox.style.top = "100px";
dialogbox.style.display = "block";
document.getElementById('dialogboxhead').innerHTML = "Are you sure?";
document.getElementById('dialogboxbody').innerHTML = dialog;
document.getElementById('dialogboxfoot').innerHTML = '<button
onclick="Alert.ok()">Cancel</button>';
document.getElementById('dialogboxfoot2').innerHTML = '<button
onclick="Alert.ok()">Continue</button>';
}
this.ok = function(){
document.getElementById('dialogbox').style.display = "none";
document.getElementById('dialogoverlay').style.display = "none";
}
}
var Alert = new CustomAlert();
</script>
<title></title>
<link rel="stylesheet" href="./css/form.css">
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<div id="dialogoverlay"></div>
<div id="dialogbox">
<div>
<div id="dialogboxhead"></div>
<div id="dialogboxbody"></div>
<div id="dialogboxfoot"></div>
<div id="dialogboxfoot2"></div>
</div>
</div>
<header>
<nav>
<div class="main-wrapper">
<div id="branding">
<!-- <li><h1><span><a href="index.php">ProjectNet</a></span></li> -->
<h1>ProjectNet</h1>
</div>
<nav>
<ul>
<li class="current"><a href="homepage.php">Home</a></li>
<li><a href="">Profile</a></li>
<li><a href="">Members</a></li>
<li><a href="">Inbox</a></li>
<li><a href="about1.php">About</a></li>
</ul>
</nav>
</nav>
</header>

<section id="showcase1">
<div class="container">
<form id="contact" action="includes/form_process.php" method="POST">
<h3>Creating a Group</h3>
<h4>Please fill out the sections below.</h4>
<fieldset>
<input placeholder="Project title" type="text" name="name">
</fieldset>
<fieldset>
<textarea placeholder="Description of the project...." type="text"
name="message" ></textarea>
</fieldset>
<fieldset>
<button onclick="Alert.render('You are about to create a new group.')"
name="submit" type="submit">Create</button>
</fieldset>
</form>
</div>
</section>
</body>
</html>

最佳答案

您似乎想“暂停”提交,直到用户确认或取消他的请求?很像一个confirm() 会做的事吗?

然后比这更复杂一点,你必须先通过返回“false”来“取消”提交(就像在 onclick="Alert.render('You are about to create a new group.'); return 之后) false”或通过调用 event.preventDefault()(并将事件添加到您的参数中)

然后您需要设计“确认”按钮,以便它执行某些操作:重新提交您的表格(这次放手)或者通过重定向或任何其他方法。

关于javascript - 表单弹出框错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49591783/

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