-1

我在标签之间有内容<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 中变量的值将是内容二。谁能帮我解决这个问题?我对php有点陌生。

4

2 回答 2

1

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

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

在脚本中

echo $_GET['content'];

将变量放入脚本的其他方式。否则,您必须围绕它制作一个表格,并使用隐藏字段发送它。

于 2012-08-24T20:45:38.880 回答
0

另一种选择是使用 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;
            });
         });
于 2012-08-24T21:06:28.090 回答