【问题标题】:Submit a form and refresh to the bottom of the page [closed]提交表单并刷新到页面底部[关闭]
【发布时间】:2017-06-25 06:38:11
【问题描述】:

在 php 中提交表单时,我使用的是:“header('Location:contact.php');”点击提交后重定向回当前页面。然而,表单位于页面底部,每次提交时都会被重定向回页面顶部。无论如何重定向回页面底部?

【问题讨论】:

标签: php html forms


【解决方案1】:

是的,你可以带一个id到你想返回的页面的一部分,然后返回,见以下代码:

比如你想返回下面的div:

<div id="bottom"></div>

你的 php 代码重定向到这个:

header('Location: contact.php#bottom');

【讨论】:

  • 这个选项应该可以正常工作,但是要注意一件事:从服务器你可以告诉客户端使用特定的哈希,但服务器永远不会收到它! (例如,content.php 不会知道 #bottom,除非它使用客户端 js)
【解决方案2】:

您可以使用 window.history 检查您的页面是否是之前的页面,如果是,请使用 window.scroll 向下滚动到。

我真的建议不要这样做并使用 AJAX

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-25
    • 1970-01-01
    相关资源
    最近更新 更多