将标记之间的内容传递到下一页


Passing content between tags to next page

我在<a>标记之间有内容,我想在单击它时将其内容传递到下一页上的变量中。

<a class="stuff" href="process.php"> Content One </a>
<a class="stuff" href="process.php"> Content Two </a>
<a class="stuff" href="process.php"> Content Three </a>

因此,如果单击中间的链接,那么传递给process.php中变量的值将是ContentTwo。有人能帮我吗?我对php有点陌生。

在脚本名称后面放一个GET参数

<a class="stuff" href="process.php?content=Content%20Two"> Content Two </a>

在脚本中

echo $_GET['content'];

另一种将变量放入脚本的方法。否则,你必须围绕这一点制作一个表格,并发送一个隐藏字段。

另一个选项是使用Jquery。您可以禁用单击链接的默认操作。然后,您可以使用javascript重定向到自动添加GET变量的页面。

$(document).ready(function() {
            $('a').click(function(event){
               event.preventDefault();
               var link = $(this).attr('href');
               var text = $(this).text();
               var url = link + '?string=' + text;
               window.location = url;
            });
         });