Javascript 清除来自php GET的消息
让我澄清一下 我有一个HTML表单,用于在名为Javascript 清除来自php GET的消息,javascript,php,html,Javascript,Php,Html,让我澄清一下 我有一个HTML表单,用于在名为contact.php的文件中发送电子邮件 在服务器端,在发送电子邮件之后,我用php编写了此文件 header('Location:contact.php?co=1'); exit(); 和在客户端(在包含表单的同一文件中) 因此,用户知道邮件是否已发送 我怎样才能澄清这个信息,“我们明白了” 我想做点像 <input name="mail" type="email" onFocus="cleatThemessage" ><b
contact.php的文件中发送电子邮件
在服务器端,在发送电子邮件之后,我用php编写了此文件
header('Location:contact.php?co=1'); exit();
和在客户端(在包含表单的同一文件中)
因此,用户知道邮件是否已发送
我怎样才能澄清这个信息,“我们明白了”
我想做点像
<input name="mail" type="email" onFocus="cleatThemessage" ><br>
因此,当用户单击表单中的字段时,消息就会消失
谢谢这可能适合您:
<?php
if ($_GET['co']) {
echo '<div id="message">We got it!</div>';
}
?>
<input name="mail" type="email" onFocus="document.getElementById('message').innerHTML = '' ;" ><br>
像这样:
Html
函数removeMessage(){
var el=document.getElementById('GoIt');
if(typeof(el)!=‘未定义’&&el!=null){
el.移除();
}
}
标题之前的(“位置:contact.php?co=1”);退出()代码>
加
和变化
if ($_GET['co']) {
if(isset($_SESSION['notification']) && $_SESSION['notification'] != '') {
echo $_SESSION['notification'];
unset($_SESSION['notification']);
}
}
为此,我假设您的表单提交到一个页面saveContact.php,在插入数据库查询后,您将其重定向到contact.php?co=1,这样,$\u SESSION['notification']='We got it'
在插入数据库查询后只执行一次。这些也称为“基于会话的flash消息”,谷歌搜索它来找到更多的方法来实现同样的目标。你使用jQuery吗?
<input name="mail" type="email" onFocus="clearThemessage(this)" ><br>
function clearTheMessage(element) {
element.value = "";
}
<?php
if(isset($_GET['co'])){
echo '<p id="gotit">We got it!</p>';
}?>
<input name="mail" type="email" onFocus="removeMessage()" >
<script type="text/javascript">
function removeMessage(){
var el = document.getElementById('gotit');
if(typeof(el) != 'undefined' && el != null){
el.remove();
}
}
</script>
$_SESSION['notification'] = "We got it";
if ($_GET['co']) {
if(isset($_SESSION['notification']) && $_SESSION['notification'] != '') {
echo $_SESSION['notification'];
unset($_SESSION['notification']);
}
}