<!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> </head> <body> <script type="text/javascript"> function calc(){ //输入的数作为数组的最大下标 + 1(数组长度) var num = parseInt(document.formA.txtNum.value); //输入的位数 //document.write(num + "<br>"); var A = 1,B = 1; //操作数 A B 的初始值 var arrays = new Array(num); arrays[0] = A; arrays[1] = B; for(var i = 2; i < num; i++){ arrays[i] = A + B; A = arrays[i - 1]; B = arrays[i]; } //document.write(array[i] + "<br>" + A + "<br>" + B); document.formA.txtResult.value = B; } </script> <form method="post" action="" name="formA"> <p> <input type="text" name="txtNum" /> </p> <p> <input type="text" name="txtResult" /> </p> <p> <input type="button" name="btnSub" value="提交" onclick="calc()" /> </p> </form> </body> </html>