点击添加一行 删除一行 改变序列号

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>点击删除序号</title>
</head>

<body>
<table>
    <tr>
        <td>1</td>
        <td>内容</td>
        <td><input type="button" value="删除" class="delete"></td>
    </tr>
</table>
<input type="button" value="添加" class="add">
</body>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $(".add").click(function(){
            var copy=$("table tr:last").clone();
            copy.appendTo("table");
            han();
                $(".delete").click(function(){
                    $(this).parents("tr").remove();
                    
                    han();
                })
            });
            
        });
        
        
        
        
        var han=function(){
            var chang=$("table tr").length;
            for(i=0; i<chang; i++){
                //$("table tr").eq(i).find('td:first').text(i+1);
            
                    $("table tr").eq(i).find('td').eq(0).text(i+1);
            
                }
            }
</script>
</html>
原文地址:https://www.cnblogs.com/jinsuo/p/6049210.html