作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个页面。接受输入并将其存储到 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 变量来做到这一点。
<a href='yourphpfilename.php?price1=xxx&YOUR2ndvariable=xxx'>Click this</a>
并通过转发到下一个 php 页面,使用简单获取此变量
$_GET['价格1']; ...
关于javascript - 如何将值从 Javascript 传递到第二页上的 php 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27976978/
我是一名优秀的程序员,十分优秀!