我試圖在將這些不斷更新的值插入到HTML表格中之前,將大量產品乘以價格。爲了示例的目的,我正在使用永久循環來不斷採取措施。爲什麼Javascript動態HTML5表沒有出現在頁面上
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
<!--
var product1 = 0;
var product2 = 0;
var product3 = 0;
var product4 = 0;
var product5 = 0;
var productNum = 0;
var productNumInt = 0;
var quantitySold = 0;
var quantitySoldInt = 0;
document.write("<table>");
document.write("<tr><th>Product Number</th><th>Quantity Sold</th></tr>");
document.write("<tr><td>1</td><td>$" + product1 + "</td></tr>");
document.write("<tr><td>2</td><td>$" + product2 + "</td></tr>");
document.write("<tr><td>3</td><td>$" + product3 + "</td></tr>");
document.write("<tr><td>4</td><td>$" + product4 + "</td></tr>");
document.write("<tr><td>5</td><td>$" + product5 + "</td></tr>");
document.write("</table>");
while (true) {
productNum = window.prompt("Please enter the product number");
quantitySold = window.prompt("Please enter the quantity sold");
productNumInt = parseInt(productNum);
quantitySoldInt = parseInt(quantitySold);
switch (productNumInt) {
case 1:
product1 += quantitySoldInt * 2.98;
break;
case 2:
product2 += quantitySoldInt * 4.50;
break;
case 3:
product3 += quantitySoldInt * 9.98;
break;
case 4:
product4 += quantitySoldInt * 4.49;
break;
case 5:
product5 += quantitySoldInt * 6.87;
break;
}
}
// -->
</script>
</head>
<body>
</body>
</html>
現在它在DOM建成之前運行! – Alexander