我有這段代碼可以正確地與for循環一起工作,如何使while和while/while循環在同樣的方式下正常工作,當我點擊按鈕時?Javascript while while do while while循環
<body>
<div>
<button onclick = "fun()">Click
</button>
<p id = "dr">
</p>
<script>
function fun() {
var str = "";
for (var i = 0; i < 11; i++) {
str = str + i + "<br/>";
document.getElementById("dr").innerHTML = str;
}
}
</script>
</div>
</body>
http://www.w3schools.com/js/js_loop_while.asp – MarcinWolny
該代碼,實際上,甚至不作爲'for'循環工作。值'I'從未定義,花括號不匹配。至於讓它成爲'while'循環,你試過了什麼?爲什麼你甚至需要改變它? – David