<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>
Run Code Online (Sandbox Code Playgroud)
本<td>Num</td>应自动递增页面上的号码.是否可以在没有任何JavaScript或其他简单解决方案的HTML中执行此操作?
您可以尝试使用counter-increment:
table {
counter-reset: tableCount;
}
.counterCell:before {
content: counter(tableCount);
counter-increment: tableCount;
}Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)
对此的支持似乎相当不错:http://caniuse.com/#feat=css-counters