Numbering dynamic table rows

前端 未结 3 958
失恋的感觉
失恋的感觉 2021-01-28 18:50

I\'m working on making a dynamic HTML table using jQuery. In a table, my user has two interactions:

  1. Append a row
  2. Remove a specific row

The

3条回答
  •  再見小時候
    2021-01-28 19:29

    After the user has appended a row, or deleted one, you just need to iterate over the "number" cells. If we assume that you have a element, we:

    1) give them a nice ID, e.g. row_0, row_1, etc...

    2) write a function to iterate over them:

    function updateRows(){
        $('[id*="row_"]').each(function(index){
            $(this).html(index + 1); // add +1 to prevent 0 index.
        };
    };
    

提交回复
热议问题