我剛開始學習java腳本幾天。一週我開始使用循環,我有相當困惑,請幫助我。如何在JavaScript中使用循環?
它不顯示X?
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script type="text/javascript">
var n,x;
n = parseInt(prompt("N", "5"));
for(i = 1; i <= n; i++) {
for(j = 1; j <= i; j++) {
x += j;
}
}
x += "<br/>";
</script>
</head>
<body>
<script type="text/javascript">
document.write("<div class=box>"+x+"</div>")
</script>
</body>
</html>
,什麼是你的問題? – 2014-08-29 05:47:34
如果你想學習他們..在這裏你去:http://www.w3schools.com/js/js_loop_for.asp – 2014-08-29 05:49:24
我可以知道爲什麼嗎? – 2014-08-29 05:56:10