<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>fibonacci</title> </head> <body> <script> // end 多少数以内 function fibonacci(end) { var num1 = 0; var num2 = 1; var num3; document.write(num1 + "<br/>"); document.write(num2 + "<br/>"); for (var i = 3; i <= end; i++) { num3 = num1 + num2; num1 = num2; num2 = num3; if (num3 > end) { break; } document.write(num3 + "<br/>"); } } fibonacci(1000); </script> </body> </html>
原文:http://www.cnblogs.com/shrekuu/p/generating-fibonacci-number-with-javascript.html