1、第一种
脚本js代码
window.onload =
function
() {
var oTable = document.getElementById("serialNumber");
for ( var i = 0; i < oTable.rows.length; i++) {
oTable.rows
[i].cells[0]
.innerHTML = (i + 1);
}
}
body代码
<table class="table table-bordered with-check">
<thead>
<tr>
<th>序号</th>
<th>岗位名称</th>
</tr>
</thead>
<tbody id="serialNumber">
<c:forEach items="${lists}" var="item" varStatus="status">
<tr onclick="trChoose(this,event.srcElement.type)">
<td></td>
<td>${item.postName}</td>
</td>
</tr>
</c:forEach>
</tbody>
</table>
2、第二种、用变量来完成
<
table class="table table-bordered with-check"
>
<thead>
<tr>
<th>序号</th>
<th>车辆类型</th>
</tr>
</thead>
<tbody id="serialNumber">
<c:forEach items="${cleanPriceLists}" var="item" varStatus="status">
<c:set var="xuHao" value="${xuHao+1}"></c:set>
<tr >
<td>${xuHao}</td>
<td>${item.typeName}</td>
</tr>
</c:forEach>
</tbody>
</table>