我有一个带有Require语句的html / php页面,其中包括另一个包含表单的页面。完成表单后,我使用Echo语句向用户显示表单提交的结果。一切正常,但是我希望页面位于底部,以便用户可以看到消息。
我尝试指定位置(bottomOfPage)并在标头命令中使用它,但是我无法使其正常工作。
你能帮我吗?
穆罕默德,我尝试按照以下方式合并您的解决方案,但它仍然无法滚动到底部:
快速表格
<?php
if(isset($_GET['send'])) //check the submit button was pressed
//从POST数组中获取变量。记住我们指定了POST方法
$fn = $_GET['firstname'];
$ln = $_GET['lastname'];
$em = $_GET['emailadd'];
$pn = $_GET['phonenum'];
$message = $fn . "\r\n" . $ln . "\r\n";
$message .= $em . "\r\n" . $pn;
$to = "trevor.reeves@webthemes.com.au";
$subject = "webThemes Contact";
//set up headers
$headers = 'From: trevor.reeves@webthemes.com.au' . "\r\n" .
'Reply-To: trevor.reeves@webthemes.com.au' . "\r\n" .
'X-Mailer: PHP/' . phpversion ();
//send the email and save the result
$result = mail ( $to, $subject, $message, $headers );
//was it sent?
if ($result) {
echo "<p>Thank you for sending the message</p>";
echo "<script>\n";
$str = "window scrollTo ( 0, document . body . scrollHeight );";
echo $str;
echo "\n</script>";
} else {
echo "<p>Sorry. An error has occurred. Please email trevor.reeves@webthemes.com.au</p>";
}
这不是问题,因为PHP脚本确实会发送电子邮件并显示消息。问题是滚动无法正常工作:
echo "<script>\n";
$str = "window scrollTo ( 0, document . body . scrollHeight );";
echo $str;
答案 0 :(得分:-1)
这是一个很好的动画
<html>
<head>
<style>
.form-submitted{
display:none;
font-weight:bold;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<form action="" method="post">
<lable for="name">Your Name</lable>
<input type="text" name="name" id="name">
<input type="submit">
</form>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<p>some content<p>
<div class="form-submitted">
<?php if(isset($_POST['name'])):?>
<script>
var success = $(".form-submitted");
success.show();
$('html,body').animate({
scrollTop: $(success).offset().top -150
}, 500);
</script>
<?php
if(isset($_POST['name'])){
echo "Your name is ".$_POST['name'];
}
?>
<?php endif;?>
</div>