2010-11-24 194 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