我遇到了这个问题,我的 Javascript 没有显示表格。假设一旦用户在其中输入 10 个数字,window.prompt
这些数字将被放入一个数组并显示到一个表格中。
这是代码:
<html>
<head>
<meta charset = "utf-8">
<script type = "text/javascript">
var number = -99;
var array1 = new Array(10);
number = window.prompt("Enter 1 to continue \n Enter -99 to exit");
if(number == -99 || number == ""){
exit();
}else
array1 = window.prompt("Please enter 10 numbers to be stored into an array");
function outputArray(heading, theArray, output){
var content = "<h2>" + heading + "</h2><table><thead><th>Index</th><th>Value</th></thead><tbody>";
var length = theArray.length;
for(var i=0; i<length;++i){
content += "<tr><td>" + i + "</td><td>" + theArray[i] + "</td></tr>";
}
content += "</tbody></table>";
output.innerHTML = content;
}
outputArray("Your Array is:", array1, document.getElementById("output"));
</script>
</head>
<body>
<div id="output"></div>
</body>
</html>