gpt4 book ai didi

javascript - 如何将值从 Javascript 传递到第二页上的 php 变量?

转载 作者:行者123 更新时间:2023-11-30 12:30:13 26 4
gpt4 key购买 nike

我有两个页面。接受输入并将其存储到 javascript 变量的一种。另一个将接收发送的变量并将其存储到 php 变量,以便我可以将其转发到数据库。

这是我第一页的代码:

<html>
<head>
<script type="text/javascript">
var pricee= 0;
var quants;
function queue(num,str){
this.pricee=num;
this.quants=str;
alert(num+" "+str);
}
function alertCurrentNumandStr(){
alert("This is the latest: "+this.pricee+" "+this.quants);
}
function send(num){
this.pricee=num;
}
</script>
</head>
<body>
<ul>
<li><script type="text/javascript">var x=42, y="alive";</script><a href="#" onclick="queue(x, y);">42 Alive</a></li>
<li><a href="#" onclick="alertCurrentNumandStr();">Get</a></li>

<li><script type="text/javascript">var t=10;</script><a href="#" onclick="send(t);">Submit</a></li>
<!--How to send this.pricee, this.quants to .php when clicking the Submit link(above)?-->
</ul>
</body>
</html>

在我的第二页上的代码:

<html>
<head>
<?php
$testNum= $_GET['pricee']
?>
</head>
<body>
<?php
echo "<h1>The num value </h1>";
echo $testNum;
?>
</body>
</html>

点击提交时如何将javascript变量传到第二页?

最佳答案

您也可以使用简单的 GET 变量来做到这一点。

  1. <a href='yourphpfilename.php?price1=xxx&YOUR2ndvariable=xxx'>Click this</a>
  2. 并通过转发到下一个 php 页面,使用简单获取此变量

    $_GET['价格1']; ...

关于javascript - 如何将值从 Javascript 传递到第二页上的 php 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27976978/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com