0

我在 div 上有一个联系表,我只想在发送邮件后隐藏 div .. 我下面的代码没有隐藏联系表

<?php 
if(mail($to,$subject,$body,$headers)) 
    { 
    echo "<script type='text/javascript'>"; 
    echo "hideDiv();" 
    echo "</script>"; 
    $msg="We have received your enquiry. We will contact you soon."; 
    } 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
<script type="text/javascript"> 
function hideDiv() 
{ 
document.getElementById("contact_form_div").style.display="none"; 
} 
</script> 
</head> 

<body> 
<form onsubmit="return validate()"> 
<!-- contact form content--> 
<input type="submit" value="submit" name="submit" /> 
</form> 
</body> 
</html>
4

2 回答 2

0

您的代码中没有 div... 您需要确定要隐藏的表单 => 添加一个 ID

<form onsubmit="return validate()" id="myID">

或者添加一个包装表单的 div

<div id="myID">
  <form onsubmit="return validate()"> 
    <!-- contact form content--> 
    <input type="submit" value="submit" name="submit" /> 
  </form>
</div>

然后通过选择 ID 隐藏表单或 div:

document.getElementById("myID").style.display="none"; 
于 2013-08-12T09:40:48.690 回答
0

如果有人关闭了 javascript,会发生什么?为什么不决定在 php 中用 if - else 显示什么?

<?php
if(mail($to,$subject,$body,$headers)) 
{
    echo "We have received your enquiry. We will contact you soon."; 
} 
else
{
?>
    <form onsubmit="return validate()"> 
        <!-- contact form content--> 
        <input type="submit" value="submit" name="submit" /> 
    </form> 
<?php
}
?>
于 2013-08-12T10:27:28.767 回答