日期:2014-05-16 浏览次数:20456 次
<!--js.php-->
<!-- 方法1 --> <?php #输出应满足javascript语法,对于输出字符串应当注意转义字符 $return=$_GET['return']; $var=$_GET['var']; $array=array("name"=>"mengdejun","age"=>22,"address"=>"hubei province","qq"=>280759843,"desc"=>"js call php"); $json=json_encode($array); echo "function add(a,b){return a+b}"; echo "var $return=$json;"; echo "var $var='http://hi.baidu.com/mak00000';"; ?> <!-- 方法2 --> function show() { alert('mengdejun'); }
?
<!--js.html-->
<script type="text/javascript" src='js.php?return=ps&var=url'></script> <script type="text/javascript"> document.write(ps.name+"<br/>"+ps.age+"<br/>"+ps.qq+"<br/>"+ps.desc); document.write("<br/>12+12="+add(12,12)); document.write("<br/><a href='"+url+"'>js调用php变量,另外一种ajax实现</a>"); show(); </script>
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
qq 360