<!DOCTYPE html>
<html>
<body>
<p>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 = "";
for (var i = 0; i < 5; i++) {
x = x + "The number is " + i + "<br>";
}
document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html>
我明白它是什么回报,但我不明白每个语句前的x。为什么x之前+“的数字是”
x = x + "The number is " + i + "<br>";
我认为这可能有助于http://en.wikiversity.org/wiki/Introduction_to_Programming/Variables#Variables - 'X = X + 1 ...将这项任务看作一个数学方程,它绝对没有任何意义 - 没有价值等于自己加上一个。但我们不是在这里谈论数学。虽然它看起来像一个等式,但它是一个变量赋值,它指出“检索X的值,添加一个值,并将结果存回X.” ' – Stuart