<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html140/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>js函数递归调用_www.jb200.com</title>
<script language="
javascript" type="text/javascript">
<!--
var msg="n 函数的递归调用 : nn";
//响应按钮的onclick 事件处理程序
function Test()
{
var result;
msg+="调用语句 : n";
msg+="result = sum(6);n";
msg+="调用步骤 : n";
result=sum(6);
msg+="计算结果 : n";
msg+="result = "+result+"n";
alert(msg);
}
//计算当前步骤加和值
function sum(m)
{
if(m==0)
return 0;
else
{
msg+="语句 : result = " +m+ "+sum(" +(m-1)+"); n";
result=m+sum(m-1);
}
return result;
}
-->
</script>
</head>
<body>
<center>
<form>
<input type=button value="测试" onclick="Test()">
</form>
</center>
</body>
</html>