<!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>无标题文档</title> <script> function fibonacci(){ var count = document.myform.txtCount.value; var fibo = new Array(count); fibo[0]=1; fibo[1]=1; for(var i = 2 ; i< count;i++){ fibo[i]=fibo[i-1]+fibo[i-2]; } for(var i=0;i < count;i++){ document.write(fibo[i]+" "); } document.write("<br>"); document.write("第"+count+"项的fibonacci的值为:"+fibo[count-1]); } </script> </head> <body> <form id="myform" name="myform" method="post" action=""> <input name="txtCount" type="text" id="txtCount" /> <input type="button" name="Submit" value="按钮" onclick="fibonacci()" /> </form> </body> </html>