【发布时间】:2018-01-26 12:36:11
【问题描述】:
这是我到目前为止所做的代码。我想超链接这些网站,以便当数组以 HTML 表格形式输出时,这些网站将是可点击的并链接到它们各自的网页。出于某种原因,type="text/javascript" 中的代码与 language="JavaScript" 中的代码不同,我不知道为什么。如果有人可以提供 language="JavaScript" 的代码,将不胜感激!
HTML:
<table id="table">
<tr id="tbody">
<th>Mattress Type</th>
<th>Link</th>
</tr>
</table>
JAVASCRIPT:
<script language="JavaScript">
var table = document.getElementById("table");
var body = document.createElement("tbody");
var beds = new Array(3);
beds[0] = ["Spring Mattress", "King Size", "http://factorymattresstexas.com/specials/spring-air/"];
beds[1] = ["Rest Lumbar Support", "Queen Size", "http://factorymattresstexas.com/specials/beautyrest-lumbar-support"];
beds[2] = ["Beauty Rest", "Twin Size", "http://factorymattresstexas.com/specials/simmons-beautyrest/"];
table.appendChild(tbody);
beds.forEach(function(items) {
var row = document.createElement("tr");
items.forEach(function(item) {
var cell = document.createElement("td");
cell.textContent = item;
row.appendChild(cell);
});
table.appendChild(row);
});
</script>
【问题讨论】:
-
脚本元素的语言属性在 HTML 4.1 中已被弃用,并在后续版本中被删除。只需将其删除。
type="text/javascript"不是必需的,它是脚本元素的默认类型。
标签: javascript html arrays html-table