开发者

how to update Sr. No. COLUMN after removing a TR from TABLE

i have a table like

<table>
<tr>
    <td>Sr. No.</td>
    <td> Name</td> 
    <td>$nbsp;</td>
</tr>
<tr>
    <td>1</td>
    <td>abc</td>
    <td>remove button</td>

</tr>
<tr>
    <td>2</td>
    <td>xyz</td>
    <td>remove button</td>
</tr>
<tr>
    <td>3</td>
    <td>def</td>
    <td>remove button</td>
</tr>

onclick of ' remove button ' i send ajax request & after successful response i remove the respective TR using $('#id_of_tr').remove();.

till here everything goes fine but now i want to update Sr. No.s of each row. Because Initially order is 1 2 3 , when i remove second row then it becames 1 3 which i want to update it to 1 开发者_JS百科2.

I hope this would help.


Like this:

// Your AJAX Call
$.post('/delete', {id: 2}, function(data){
  // your code that removes the tr here

  $('table tr').each(function(index, el){
    $(this).find('td:first').text(index + 1);
  })
})
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜