我跟着一個非常基本的瓶啤酒教程(不同於本網站上已提及的),我不明白這部分正在做什麼:瓶啤酒 - 這是什麼:var bottlesDiv =文檔
var bottlesDiv = document.
全部代碼在這裏(和它如預期工作):
var bottles = 99;
var lyrics = "";
while (bottles > 0) {
lyrics = lyrics + bottles + " bottles of beer on the wall <br>";
lyrics = lyrics + bottles + " bottles of beer <br>";
lyrics = lyrics + "Take one down, pass it around, <br>";
bottles = bottles - 1;
if (bottles > 0) {
\t lyrics = lyrics + bottles + " bottles of beer on the wall <br><br>";
} else {
\t lyrics = lyrics + "No more bottles of beer on the wall. <br>";
}
}
var bottlesDiv = document.
getElementById("bottles");
bottlesDiv.innerHTML = lyrics;
<!doctype html>
<html lang="en">
<head>
\t <title>99 Bottles of Beer</title>
\t <meta charset="utf-8">
\t <link rel="stylesheet" href="style.css">
</head>
<body>
\t <h1>99 Bottles of Beer </h1>
\t <div id="bottles"></div>
</body>
</html>
該行只是一半的陳述。如果你使用下面這行代碼加入它,代碼就更容易理解了:var bottlesDiv = document.getElementById(「bottles」);' – acbabis 2015-02-06 23:17:21