使用下面的代码,我得到了意想不到的结果:
function myFunction() {
var text = "something";
var i;
for (i = 0; i < 5; i++) {
text += "The number is " + i + "<br>";
}
document.getElementById("demo").innerHTML = text;
}
<p>Click the button to loop through a block of code five times.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
结果是:
somethingThe number is 0
The number is 1
The number is 2
The number is 3
The number is 4
为什么我没有得到下面的结果?
somethingThe number is 0
somethingThe number is 1
somethingThe number is 2
somethingThe number is 3
somethingThe number is 4