使用javascript调用Php中的函数

I am using a php function to count when mouse moves. Its called inside java script. However, function is called ones but prints the same value when called for second time. Code goes like this. Every times it alerts 0 instead of counting.

<?php 
$i=0;
function page($i)

{
echo $i;
$i++;
}
//page()
?>

<html>
<head>

<title>onmousemove test</title>

<script type="text/javascript">

window.onmousemove = move;
function move() {
alert("<?PHP page($i);?>");
}
</script>
</head>

Raj,

PHP is a server-side language whereas Javascript is a client-side language. Meaning, your web server sends HTML and Javascript code to the browser so that the browser can execute it. Your browser doesn't execute PHP. So if you look at the source code of what you are sending to the browser, your JavaScript function will look like this:

window.onmousemove = move;
function move() {
alert("0");
}

Your script will only print 0 because javascript cannot access PHP function. You will need to write your page function in Javascript and do something like

int i = 0;
function page(){Console.log("page i = " + i); i++;}    
function move(){ alert(page()); }