简体   繁体   English

锚链接的自动递增网址

[英]Autoincrement url for anchor link

I am trying to make anchor links for different sections in the page. 我正在尝试为页面中的不同部分创建锚定链接。

#section1 #section2 #section1#section2

But, the url isn't being updated each time I click the href link 但是,每次我单击href链接时,URL都不会更新

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

When I echo the counter I can see it being updated upon refresh but I want to be able update the anchor section without refreshing. 当我回显计数器时,我可以看到它在刷新时被更新,但是我希望能够在不刷新的情况下更新锚定部分。

Thank you 谢谢

You need to actually increment the value in the session and not just what is currently stored in the session. 您实际上需要增加会话中的值,而不仅仅是增加会话中当前存储的值。

 // 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