跳转到表单提交到新页面的页面顶部

时间:2015-11-16 11:51:11

标签: javascript php html forms

我在PHP页面上有一个表单:

<form name="SendEmail01" method="post">
    form items here...
</form>

然后我按照这样处理:

if(isset($_POST["Submit"]))
{
All tasks here...
$thanks_redirect = 'http://' . $_SERVER["SERVER_NAME"] . '/thanks.php#top';
header("location: $thanks_redirect");
}

问题是处理页面上的提交按钮在页面上相当低,当我按“提交”时,它都正确处理并正确跳转到thanks.php页面,但页面停留在同一位置看起来它只是一个空白页面(除非用户向上滚动)。

我已经尝试过Javascript和HTML超链接,例如#top但它不会跳回到页面顶部,在thanks.php页面上,它表示已经正确处理了所有这些。

有没有人可以帮我解决一下表格处理完毕后如何将thanks.php页面滚动回页面顶部?

编辑:我在thanks.php页面上有这个,用户在提交时被重定向:

<html>
<head>
<script type="text/javascript">
var lockit=setInterval("window.scrollTo(0,0)",10)
</script>
<style>
form {
    display: inline;
}
input
{
color: #000000;
background: #ffffff;
border: 1px solid #000000;
padding: 4px;
font-size:13px;
font 
}
#submit {
 color: #000000;
 font-size: 13px;
 width: 110px;
 height: 30px;
 border: 1px solid #000000;
 margin: 0;
 padding: 0;
 background: #66ff66 url(image) 0 0 no-repeat; 
}
#buttons {
 color: #000000;
 font-size: 13px;
 width: 80px;
 height: 25px;
 border: 1px solid #000000;
 margin: 0;
 padding: 0;
 background: #66ff66 url(image) 0 0 no-repeat; 
}
</style>

</head>
<body>
<script type="text/javascript">
$('html, body').animate({ scrollTop: 0 }, 'fast');
</script>
<?php
session_start();
$loggedin_user = $_SESSION['serial'];
$local_path = $_SESSION['local_path'];
$full_path = $_SESSION['full_path'];
?>
<font face="Verdana, Arial, Helvetica, sans-serif" color="black">

<form action="http://<?php echo $_SERVER["SERVER_NAME"]; ?>/login.php?log_out">
    <input type="submit" value="Logout" id="buttons">
</form>
<form action="<?php echo $full_path;?>index.php">
    <input type="submit" value="Go Back" id="buttons">
</form>
<p><b>Success!</p></b>
<p>Your changes have been submitted.. 

<p>Please note that not <u>all</u> changes are made in real-time, some changes may only be updated when the server checks for new configuration.</p>

</body>
</html>

谢谢。

2 个答案:

答案 0 :(得分:0)

我会将其添加为评论,但它有点太长了。

我做了这个页面:

<!DOCTYPE html>
<html>
<head>
</head>

<body>

    <p>Calibri Text</p>
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <form>
        <input type="submit" />
    </form>

</body>
</html>

在提交时,页面会跳转到顶部并重定向到另一个页面,因此您不应该遇到此问题,因为jQuery中的某些内容会给予关注。

答案 1 :(得分:0)

试试这个。

$('html, body').animate({ scrollTop: 0 }, 'fast');

您不需要任何custom divs。只需要一个简单的页面。

<html>
<head>
<title>Thanks Page</title>
</head>
<body>

Well Thanks bro!

</body>
</html> 
相关问题