最近做一項目,需要對數據進行排序輸出,要求有行號,依次遞增1.2.3.4.5.......。
前端通過<c:forEach> 遍歷動態輸出的<tr>,代碼如下:
<!-- 循環生成,列表數據 --> <c:forEach items="${pager.list}" var="auction"> <tr class="bg1"> <td width="10" align="center"><span class="numberClass"></span></td> <td width="30" align="center">${auction.dept}</td> <td width="40" align="center">${auction.donor}</td> <td width="40" align="center">¥:${auction.auctionSum}.00</td> <td width="40" align="center"><span onClick="displayDetails('xxxx}')" style="color:blue;cursor:pointer;">查看詳細信息</span></td> </tr> </c:forEach>
行號自增js代碼(需引入jquery):
$(function(){ function number(){ for(var i=0;i< $(".numberClass").length;i++){ $(".numberClass").get(i).innerHTML = i+1; } } number(); });