簡體   English   中英

錨鏈接的自動遞增網址

[英]Autoincrement url for anchor link

我正在嘗試為頁面中的不同部分創建錨定鏈接。

#section1#section2

但是,每次我單擊href鏈接時,URL都不會更新

 if(!isset($_SESSION['counter'])) {
     $_SESSION['counter'] = 1;
 }
 <?php echo '<a href = "#section'.($_SESSION['counter']++).'">'.'Next Section'.'</a>';?>

當我回顯計數器時,我可以看到它在刷新時被更新,但是我希望能夠在不刷新的情況下更新錨定部分。

謝謝

您實際上需要增加會話中的值,而不僅僅是增加會話中當前存儲的值。

 // If there is a value in the session, then increment it. 
 if(isset($_SESSION['counter'])) {
     $_SESSION['counter'] = $_SESSION['counter'] + 1;
 } else {
     $_SESSION['counter'] = 1;
 }

// Now, use the value which you have set. 
<?php echo '<a href = "#section'.($_SESSION['counter']).'">'.'Next Section'.'</a>';?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM