这是我迄今为止所做的代码。我想要超链接这些网站,以便当数组以HTML形式输出时,这些网站将是可点击的,并链接到它们各自的网页。是否可以在HTML中的表格中输出JavaScript数组元素作为超链接?
的JavaScript:
var beds = new Array(3);
beds[0] = ["Spring Mattress", "http://factorymattresstexas.com/specials/spring-air/"];
beds[1] = ["Rest Lumbar Support", "http://factorymattresstexas.com/specials/beautyrest-lumbar-support"];
beds[2] = ["Beauty Rest", "http://factorymattresstexas.com/specials/simmons-beautyrest/"];
HTML:
var table = document.getElementById("table");
var body = document.createElement("tbody");
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);
});
<table id="table">
<tr id="tbody">
<th>Mattress Type</th>
<th>Link</th>
</tr>
</table>
怎么样,而不是在设置'text'的细胞,创建一个链接元素和追加,与其 – musefan
是的,这是绝对有可能。你知道如何从单个字符串中创建单个链接('A'元素)吗? –