CSS
html
js
代码复制如下
CSS
<style>
table {
width: 800px;
border: 1px solid #333;
border-collapse: collapse;
text-align: center;
}
th,
tr,
td {
border: 1px solid #333;
}
</style>
--------------------------------------------------------------------------------------------
html
<body>
<table class="table">
<thead>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<!-- <th>价格</th>
<th>数量</th>
<th>小计</th>
<th>操作</th> -->
</tr>
</thead>
<tbody class="tbody">
</tbody>
</table>
-------------------------------------------------------------------
js
<script type="text/javascript">
let goodsList = [{ 1: '我', 2: '我', 3: '123' }, { 1: '678', 2: '678', 3: '678' }, { 1: '他', 2: '他', 3: '他' }]
// 创建元素节点,根据关系形成页面
var tbody = document.getElementsByClassName('tbody')[0]
for (var i = 0; i < goodsList.length; i++) {
var tr = document.createElement('tr')
tbody.appendChild(tr)
for (var k in goodsList[i]) {
var td = document.createElement('td')
td.innerHTML = goodsList[i][k]
tr.appendChild(td)
}
}
</script>
</body>