2014-10-01 72 views
3
<table> 
     <tr> 
      <td>Num</td> 
      <td>Name</td> 
     </tr> 
     <? foreach {{ ?> 
     <tr> 
      <td>here this must be html auto increment number</td> 
      <td>this will be from database</td> 
     <tr> 
     <? endforeach; ?> 
    </table> 

<td>Num</td>應自動遞增頁面上的編號。 是否可以在沒有任何JavaScript或其他簡單解決方案的HTML中執行此操作?html,一列自動增量編號

+2

看看'反increment'(CSS)。 http://www.w3schools.com/cssref/pr_gen_counter-increment.asp – bzeaman 2014-10-01 08:30:42

+0

您使用的是什麼serverlanguage? PHP?您可以將您的foreach更改爲for循環,例如:for($ i = 0; $ i Sasse 2014-10-01 08:30:45

+0

這沒關係每個人都不是這裏的意思 – SAR 2014-10-01 08:31:17

回答

3

您可以嘗試使用counter-increment:針對

table { 
 
    counter-reset: tableCount;  
 
} 
 
.counterCell:before {    
 
    content: counter(tableCount); 
 
    counter-increment: tableCount; 
 
}
<table> 
 
    <tr> 
 
    <td>Num</td> 
 
    <td>Name</td> 
 
    </tr> 
 
    <tr> 
 
    <td class="counterCell"></td> 
 
    <td>this will be from database</td> 
 
    </tr> 
 
    <tr> 
 
    <td class="counterCell"></td> 
 
    <td>this will be from database</td> 
 
    </tr> 
 
</table>

支持似乎不錯:http://caniuse.com/#feat=css-counters