2010-11-24 227 views
2

我在我的网页底部有一个表单,当我提交表单和页面刷新时,我希望页面自动地位于页面的底部,以便我看到表单再次。是否有可能实现这一点,而不使用任何JavaScript,只能使用PHP。自动滚动到页面底部

回答

4

是的。您可以使用链接的name attribute执行此操作。

在你的页面的底部有这样的代码:

<!-- The page with the form (script.php) --> 
<?php 
    //Other page content 
?> 
<a name="bottomOFThePage"></a> 
<?php 
//Your form 
?> 

<!-- 
    PHP page that handles the form submit 
    Use the header code from netcoder's answer below 
--> 
<?php 
    //Process your form 
header('Location: script.php#bottomOfPage'); 
?> 

重定向您提交表单后http://yoururl.com/script.php#bottomOfThePage

+0

好,但我怎么能做到这一点使用codeigniter .. !!? :( – goseo 2013-03-28 08:53:35

2

做到这一点没有JavaScript的最好办法就是把锚标签底部你的页面:

<a name="bottomOfPage"></a> 

然后,将用户重定向到该页面的底部(或提交表单):

<?php 
header('Location: script.php#bottomOfPage'); 
exit; 
+0

`href`?你的意思是`name`,是吗? – 2010-11-24 19:57:11