源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p>如果计算出最大可能数以外的值,则返回Infinity.</p> <button onclick="myFunction()">试试</button> <p id="demo"></p> <script> function myFunction() { var myNumber = 2; var txt = ""; while (myNumber != Infinity) { myNumber = myNumber * myNumber; txt = txt + myNumber + "<br>"; } document.getElementById("demo").innerHTML = txt; } </script> </body> </html>
运行结果