javascript - 如何增加表格单元格的值?

标签 javascript jquery html-table

我不明白如何增加表格单元格的值,例如:1、2、3 等?

我的代码:

$('#table').each(function(i){
    $(this).find('td:nth-child(1)').text(i);
});

请看full example .

最佳答案

我认为this是你想要的:

var i = 1;
$('#table').find('td:nth-child(1)').each(function()
                                         {
                                             $(this).text(i++);
                                         });

simpler :

$('#table').find('td:nth-child(1)').each(function(i)
                                         {
                                             $(this).text(i + 1);
                                         });

关于javascript - 如何增加表格单元格的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3940145/

相关文章:

html - 我怎样才能得到一个 html 表格单元格,它是一个包含文本和另一个链接的链接?

javascript - 将 geojson 元素获取到 html 表中

javascript - 如何在 Keystone.js List Map 中指定多个字段?

javascript - 消失的转变

html - 使输入字段在长类型上增长

javascript - 将数值替换为另一个

javascript - CSS 悬停 - parent 也会受到影响。如何避免这种情况?

javascript - 如何在 Django 应用程序上使用静态 Javascript 播放静态 mp3 文件?

javascript - 如何从按钮数组中识别按钮点击

javascript - 使用 jQuery 加载文档的响应图像大小