<!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