<script language="text/javascript">
function factorial(x) {
if (x <= 1)
return 1;
return x * factorial(x-1);
}
</script>
<?php
print (factorial(5)); ////// 9
?>Fatal error: Call to undefined function factorial() in F:\apache\js\test2.php on line 9
function factorial(x) {
if (x <= 1)
return 1;
return x * factorial(x-1);
}
</script>
<?php
print (factorial(5)); ////// 9
?>Fatal error: Call to undefined function factorial() in F:\apache\js\test2.php on line 9
你在php代码中使用一个在Javascript中定义的函数
<?php
function factorial(x) {
if (x <= 1)
return 1;
return x * factorial(x-1);
}
print (factorial(5)); ////// 9
?>
要么如上写要么用php重新实现factorial,在php这样用
不行啊
function factorial($x) {
if ($x <= 1) return 1;
else return $x * factorial($x-1);
}
print (factorial(5)); ////// 9
?>
要想实现你的想法,可以js和php分开执行,c/s的做法,用ajax把前客户端的js数据传给服务端的php。
life169真够耐心的.我是真的差点崩溃了...