【发布时间】:2018-12-15 16:44:48
【问题描述】:
我有一个带有 Require 语句的 html / php 页面,其中包括另一个包含表单的页面。表单完成后,我使用 Echo 语句向用户显示表单提交的结果。一切正常,但我希望页面将自身定位在底部,以便用户可以看到消息。
我已经尝试指定一个位置 (bottomOfPage) 并在标题命令中使用它,但我无法让它工作。
你能帮帮我吗?
Mohammad,我尝试按如下方式合并您的解决方案,但它仍然无法滚动到底部:
快速表格<?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;
【问题讨论】:
-
window.scrollTo(0,document.body.scrollHeight); -
这不是问题,因为 PHP 脚本会发送电子邮件并显示消息。问题是滚动不起作用: