对 javascript 和 html 类型的东西非常陌生。我只想使用来自用户的输入并将其输出到表格中来做一个简单的示例。我无法让窗口提示实际出现。我想有一些非常明显的事情表明我做错了,但我目前没有看到它......我正在学校上课,但这不是家庭作业,只是我自己做的练习。
这与while循环有关吗?关于我应该如何继续提示用户的任何建议,直到他们另有说明?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Mileage Record</title>
<style type = "text/css">
table {
width:300px;
border-collapse:collapse;
background-color:lightblue;
}
table, td, th {
border: 1px solid black;
padding: 4px;
}
th {
text-align: left;
color: white;
background-color: darkblue
}
tr.oddrow {
background-color: white;
}
</style>
<script>
var milesDriven;
var gallonsUsed;
var mpg;
var anyMore;
document.writeln("<table>");
document.writeln("<thead><tr><th>Miles Driven</th>");
document.writeln("<th>Gallons Used</th>");
document.writeln("<th>MPG</th>");
document.writeln("</tr></thead><tbody>");
while (anyMore == true) {
milesDriven = window.prompt("How many miles did you drive?");
gallonsUsed = window.prompt("How many gallons did you use?");
mpg = milesDrive/gallonsUsed;
document.writln("<tr><td>" + milesDriven + "</td><td>" +
gallonsUsed + "</td><td>" + mpg + "</td></tr>");
anymore = confirm("Do you have any more data to input?");
}
document.writeln("</tbody></table>");
</script>