我在 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>
谢谢。
最佳答案
我想将其添加为评论,但对它来说有点太长了。
我做了这个页面:
<!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 中有一些东西提供了焦点。
关于javascript - 在表单上跳转到页面顶部提交到新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33734714/