今天在百度知道里看到这个问题,于是就写了下面的代码,希望可以帮到需要的人
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Fibonacci数</title>
<script language="javascript">
function a(){
var a = document.getElementById("a").value;
var F = [];
F[1] = 1;
F[2] = 1;
n = 3;
do{
F[n] = F[n-1] + F[n-2];
n++;
}while(n<=a)
var sum ="";
var sm = "";
for(var i=1 ;i<=a; i++){
sum += "F["+i+"]="+F[i]+" ";
sm += F[i] + " ";
}
document.getElementById("b").innerHTML = "F["+a+"]="+F[a];
document.getElementById("c").innerHTML = sum +"<br />"+sm;
}
</script>
</head>
<body>
<input type="text" name="a" id="a" value="" />
<button onclick="javascript:a()">查看</button><br />
<a id="b"></a><br />
<a id="c"></a>
</body>
</html>