0
我的html代碼應該接收輸入項目及其編號的列表,然後顯示數組,然後按照數字的降序排列。但我甚至可以讓我的代碼將數組輸出到表格單元格。我可以通過它來正常輸出數組,但是我想保留整個頁面的樣式,並且讓數組輸出我想要的特定表格單元格。我不能讓數組輸出顯示在表格單元格中。我該怎麼做?
<html>
<head><link rel="stylesheet" type="text/css" href="css_styling.css" /></head>
<body onload="start()"><div id="container">
<div id="wrapBanner"><div id="banner">
<img src="banner.png" alt="banner" />
</div></div>
<div>
<table border="1">
<tr><th class="title" colspan="2">Unsorted List</th></tr>
<tr><td class="subhead">Item</td><td>Quantity</td></tr>
<tr><td class="subhead">
<script language="javascript" type="text/javascript">
var arr_size = 5;
function start ()
{
var a1 = new Array(arr_size);
var a2 = new Array();
for (var i=0; i<arr_size; i++)
{
a1[i] = prompt ("Enter the Item Name");
a2[i] = prompt("Enter Item Number");
}
outputArray("Array two contains", a1);
outputArray("Array two contains", a2);
}
function outputArray (header, the_array)
{
document.write("<h2>"+header+"</h2>"+"<br />");
document.write("<table border=\"1\"><thead><th align=\"left\">");
document.write("Index</th></thead>");
document.write("<tbody>");
for (var i=0; i<arr_size;i++){
document.write("<tr><td>" + the_array[i] + "</td></tr>");
document.write("</tbody></table>");
}
</script>
</td>
</tr>
</table>
</div>
</div></body>
</html>
</body>
</html>`