1 回答
TA贡献1840条经验 获得超5个赞
使用script标签代替import. export在js文件中删除。
<script type="text/javascript" src="data.js"></script>
1.html
<table id="table">
<tr>
<th>ID</th>
<th>Name</th>
<th>Category</th>
<th>Color</th>
</tr>
</table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="data.js"></script>
<script>
for (var i = 0; i < data.length; i++) {
var row = "<tr><td>" + data[i].id + "</td>";
row += "<td>" + data[i].name + "</td>";
row += "<td>" + data[i].category + "</td>";
row += "<td>" + data[i].color + "</td></tr>";
$("#table").append(row);
}
</script>
数据.js
var data = [
{
id: "001",
name: "apple",
category: "fruit",
color: "red",
},
{
id: "002",
name: "melon",
category: "fruit",
color: "green",
},
{
id: "003",
name: "banana",
category: "fruit",
color: "yellow",
},
];
添加回答
举报