JS sort output to achieve the table line number from the front end of the dynamic generation of tr

  • 2020-03-30 03:40:20
  • OfStack

For a recent project, it is necessary to sort the output of the data, which requires the line number and the sequential increment of .

Front pass < C: forEach> Traversing dynamic output < Tr> , the code is as follows:

<!--  Loop generate list data  --> 
<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"> RMB: ${auction.auctionSum}.00</td> 
<td width="40" align="center"><span onClick="displayDetails('xxxx}')" style="color:blue;cursor:pointer;"> View details </span></td> 

Line number self-increment js code (jquery is needed) :

function number(){ 
for(var i=0;i< $(".numberClass").length;i++){ 
$(".numberClass").get(i).innerHTML = i+1; 

Related articles: