简体   繁体   English

删除表jquery中所有行ID旁边的行更改

[英]Remove row change next all row id in table jquery

Im using yii-editable-grid 我正在使用yii-editable-grid

Example: 例:

<tbody>
    <tr id='0'> <td>Row 1</td> <td>Delete</td></tr>
    <tr id='1'> <td>Row 2</td> <td>Delete</td></tr>
    <tr id='2'> <td>Row 3</td> <td>Delete</td></tr>
    <tr id='3'> <td>Row 4</td> <td>Delete</td></tr>
</tbody>

When Delete Row 2 should change the ID of next row in a table 何时删除第2行应更改表中下一行的ID

<tbody>
      <tr id='0'> <td>Row 1</td> </tr>      
      <tr id='1'> <td>Row 3</td> </tr>
      <tr id='2'> <td>Row 4</td> </tr>
 </tbody>

Please anyone help to resolve this ? 请任何人帮助解决此问题?

try 尝试

$("tr").click(function () {
    $(this).remove();
    $("tr").prop("id", function () {
        return $(this).index();

    });
});

DEMO DEMO

use nextAll() , to stop unwanted changes 使用nextAll() ,停止不需要的更改

$("tr").click(function () {
    var id = this.id;
    $(this).nextAll("tr").prop("id", function () {
        return id++;
    });
    $(this).remove();

});

DEMO DEMO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM