所以我有我的表起來和運行,但我無法添加一個有效的「malito」鏈接到我的表,並沒有任何好的例子,我可以找。我試過類似如何通過JS文件添加鏈接到表格
"<td>" + <a href = "users[i].email"> + </a> + "</td>" +
但它不起作用=。
var users = [
{first_name: "Kaitlin", last_name: "Burns", age: 23, email: "[email protected]"},
{first_name: "Joshua", last_name: "Feir", age: 31, email: "[email protected]"},
{first_name: "Stephen", last_name: "Shaw", age: 28, email: "[email protected]"},
{first_name: "Timothy", last_name: "McAlpine", age: 37, email: "[email protected]"},
{first_name: "Sarah", last_name: "Connor", age: 19, email: "[email protected]"}
];
window.onload = function()
{
var tableContainer = document.querySelector("#outputTable");
var table = "";
for (var i = 0; i < users.length; i++)
{
table += "<tr>" +
"<td>" + users[i].first_name + "</td>" +
"<td>" + users[i].last_name + "</td>" +
"<td>" + users[i].age + "</td>" +
//Email link here
"</tr>";
}
tableContainer.innerHTML += table;
};
HTML文件
<h3> Information </h3>
<head>
<script src = "js/table.js"></script>
</head>
<body>
<table id = "outputTable" border = "1">
<thead style = "background-color: orangered;">
<tr>
<th> First Name </th>
<th> Last Name </th>
<th> Age </th>
<th> Email </th>
</tr>
</table>
</body>
這是我的表看起來如何
Information
First Name Last Name Age Email
Kaitlin Burns 23
Joshua Feir 31
Stephen Shaw 28
Timothy McAlpine 37
Sarah Connor 19
修正了它,但沒有任何變化 –