我想显示我的表格列表的索引,而不需要单击,这在SO和其他来源的大多数示例中都是如此。
<script src="../js/jquery-2.0.2.min.js"></script>
<table id="tableID" width="200" border="1">
<tr>
<td class="sm">5</td>
<td class="pos"></td>
</tr>
<tr>
<td class="sm">4</td>
<td class="pos"></td>
</tr>
<tr>
<td class="sm">5</td>
<td class="pos"></td>
</tr>
</table>
<script>
var position = getElementsByClassName("pos").index();;
document.getElementsByClassName("pos")[0].textContent = position;
</script>
我希望上表给出这样的结果
最佳答案
$('td.pos').each(function(){
$(this).html($(this).parent().index()+1);
});
这是DEMO
关于javascript - 如何指示动态表列表中 <tr> 表行的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38577929/