新手请教PHP$a++的问题

WBOY
Release: 2016-06-23 13:41:58
Original
854 people have browsed it

代码如下
$a=1;
?>
<script> <br /> function add(){ <br /> alert(<?php echo $a ?>); <br /> <?php $a++; <br /> ?> <br /> </script>

我想实现每次click的时候$a会自增 即第一次alert "1"第二次alert "2" 类推.但我发现每次$a都会变为1 而没有自增.不明白 请教各位高手 


回复讨论(解决方案)

网页加载完后php代码不会再调用了,
加载完过后js的函数就变成了

function add(){alert(1);}
Copy after login

你查看一下网页的源代码就看出来了

楼上说的不错。 php是服务器端运行的,只返回运行的结果。客户端的操作,不会再执行php了。

可以使用静态去定义变量。

php不会在客户端执行的而是服务器端,你都用apapche处理php,js是在客户端执行,而是也不能是js嵌套php代码,我只试过php嵌套js代码

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!