JavaScript中for循环使用代码演示,下面的代码演示了一个简单的for循环语句输出0到4的数字
<!DOCTYPE html> <html> <body> <p>75271.com,Click the button to loop through a block of code five times.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var x="",i; for (i=0;i<5;i++) { x=x + "The number is " + i + "<br>"; } document.getElementById("demo").innerHTML=x; } </script> </body> </html>