返回信息流其实我就是想php代码中红色的值传到下面的<script>里面用,应该不难,听说smarty可以实现,但是我没弄懂,小白求指教
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
#content
{
width:1200px;
height:600px;
margin:0 auto;
}
.frame{
width:674px;
height:504px;
margin:20px 30px;
padding:10px 10px;
float:left;
border:3px solid white;
border-radius:3px
}
.flame{
width:354px;
height:504px;
margin:20px 30px;
padding:10px 10px;
float:left;
border:3px solid white;
border-radius:3px
img{
width:500px;
height:500px;
}
</style>
<title>单支节匹配
</title>
</head>
<body style="background-color: #CCC;">
<div id="content">
<h1 style="text-align:center">单支节匹配--并联开路线法</h1>
<div id="album">
<div class="flame">
<form name="form4" method="post" action="">
<label for="remind">
<div align="center" style="font-size:30px;">请输入电路参数</div>
</label>
</form>
<form action="stub.php" method="post">
<p><strong>特性阻抗:</strong>
<input type="text" name="s" />(Ω)
</br>
</p>
<p><strong>负载阻抗:</strong>
<input name="a" type="text" size="6" />+<input name="b" type="text" size="6" />
j(Ω)
</p>
<div align="center">
<input name="计算匹配值" type="submit" value="计算匹配值" />
</div>
</form>
<?php
$s=$_POST["s"];
$a=$_POST["a"];
$b=$_POST["b"];
$f=$_POST["f"];
$th=atan((2*$b*$s)/($a*$a+$b*$b-$s*$s));
$k=($a-$s)*($a-$s)+$b*$b;
$p=($a+$s)*($a+$s)+$b*$b;
$gama=sqrt($k/$p);
$radius=$gama*220;
$rho=(1+$gama)/(1-$gama);
$d01=atan(1/sqrt($rho))/6.283185307;
$d02=0.5+atan(-1/sqrt($rho))/6.283185307;
$lmax=$th/12.566370614;
$d1=$lmax+$d01;
$d2=$lmax+$d02;
if($d1>0.5)
$d1=$d1-0.5;
else
$d1=$d1;
end;
if($d2>0.5)
$d2=$d2-0.5;
else
$d2=$d2;
end;
$l1=atan(($rho-1)/sqrt($rho))/6.283185307;
$l2=0.5+atan((1-$rho)/sqrt($rho))/6.283185307;
?>
<form name="form5" method="post" action="">
<label for="result">
<div align="center" style="font-size:30px;">
<p><br>
计算结果</p>
</div>
<strong>D的长度为:</strong> <?php echo $d1; ?>λ 或<?php echo $d2; ?>λ<br />
<strong>L的长度为:</strong> <?php echo $l1; ?> λ 或<?php echo $l2; ?>λ
<br />
</form>
</div>
<div class="frame">
<canvas id="myCanvas" width="674" height="504" style="border:2px solid blue;">
您的浏览器不支持。
</canvas>
<script type="text/javascript">
var smith=document.getElementById("myCanvas").getContext("2d");
smith.fillStyle="rgba(192, 80, 77, 0)";
smith.strokeStyle="black";
smith.lineWidth=1;
smith.beginPath();
smith.arc(250,250,220,0,Math.PI*2,true);
smith.closePath();
smith.fill();
smith.stroke();
smith.fillStyle="rgba(192, 80, 77, 0)";
smith.strokeStyle="black";
smith.lineWidth=1;
smith.beginPath();
smith.arc(360,250,110,0,Math.PI*2,true);
smith.closePath();
smith.fill();
smith.stroke();
smith.beginPath();
smith.moveTo(504,250);
smith.lineTo(0,250);
smith.stroke();
smith.beginPath();
smith.moveTo(250,504);
smith.lineTo(250,0);
smith.stroke();
smith.fillStyle="rgba(192, 80, 77, 0)";
smith.strokeStyle="black";
smith.lineWidth=1;
smith.beginPath();
smith.arc(250,250,100,0,Math.PI*2,true);
smith.closePath();
smith.fill();
smith.stroke();
</script>
</div>
</div>
</div>
</body>
</html>
这是一条镜像帖。来源:北邮人论坛 / www-technology / #20559同步于 2013/6/22
该镜像源已超过 30 天没有更新,可能在源站已被删除。
WWWTechnology机器人发帖
[问题]php如何向js传值,一个小问题 求指教
qazshi
2013/6/22镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
php文件的好处就是在文件的任何位置有php的tag包括起来的位置都会被php解析.在你想要的位置写上<?php echo $radius; ?>就行了 比如直接在script里面写var aaa = '<?php ?>';这种都行.简单的页面用smarty学习成本高效率低
json... 用 json_encode函数,将数组转换为json 然后传给js
笨办法是讲内容写入隐藏元素,然后使用js读取元素内容。不过这样不能异步。。