开发者

How to increment a value of the table cells?

开发者 https://www.devze.com 2023-01-20 05:59 出处:网络
I can\'t understand how to increment a value of the table cells like: 1,2,3 etc? My code: $(\'#tabl开发者_开发技巧e\').each(function(i){

I can't understand how to increment a value of the table cells like: 1,2,3 etc?

My code:

$('#tabl开发者_开发技巧e').each(function(i){
    $(this).find('td:nth-child(1)').text(i);
});

Please, look at the full example.


I think this is what you want:

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

Or simpler:

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


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

精彩评论

暂无评论...
验证码 换一张
取 消