php - php滚动到页面底部后,div中的消息没有被执行
问题描述
我在 PHP 中有一个联系表。发送邮件后,我想要滚动到页面底部的功能,以便用户可以查看邮件是否已发送。如果邮件已发送/发送失败,我们会使用 div 的警报类收到错误消息。但是,在页面滚动到底部后,我无法看到警报框,但是如果我删除滚动到底部功能,即使在邮件发送后我也能够看到警报消息。谁能指导我哪里错了。
<?php
//validation done here
if(mail($toEmail, $subject, $body, $headers)){
// Email Sent
$msg = 'Your email has been sent';
$msgClass = 'alert-success';
} else {
// Failed
$msg = 'Your email was not sent';
$msgClass = 'alert-danger';
}
header('Location:index.php#bottomOfPage');
?>
//remaining html goes here
<?php if($msg != ''): ?>
<div class="alert <?php echo $msgClass; ?>"><?php echo $msg; ?></div>
<?php endif; ?>
<a name="bottomOfPage"></a>
//form is here
解决方案
Please move the 'bottomOfPage' name tag above the success/failure message displaying
Try the code like below
<a name="bottomOfPage"></a>
<?php if($msg != ''): ?>
<div class="alert <?php echo $msgClass; ?>"><?php echo $msg; ?></div>
<?php endif; ?>
推荐阅读
- javascript - 尝试代理时出错:localhost:4200/api/v1/generate_uid
- android - 在 BottomNavigationView 中垂直对齐图标
- python-3.x - Spacy pos 标记 PPER
- c# - C# 从另一个类更改创建的对象值
- c++ - 佳能 EDSDK 13.11.10 未保存到主机 PC
- rust - 如何将上传的文件保存到文件夹?
- angular - 关闭 refCount 的 rxjs shareReplay 在第一个下游订阅者之前不会订阅源
- r - 将数据帧列表取消列出到一个具有更改结构的数据帧
- visual-studio - 在 Visual Studio 中,如何将文件的不同版本发布到 Mac 和 PC (.Net Core)
- python - 打开并立即使用没有上下文管理器的文件是否危险?