删除后在javascript中对附加表行重新编号

删除后在javascript中对附加表行重新编号,javascript,jquery,Javascript,Jquery,嗨,我有这些代码来删除一个表行,我的问题是,当我删除一个在数字之间的行时,例如我有4行,我删除了第2行,行的编号将类似于1,3,4。。但我需要它是1,2,3,我怎样才能做到这一点?谢谢你的帮助 下面是我如何动态添加表的 $('#mhTable').on('click', '.DeleteRow', function() { if(confirm("Are you sure you want to delete this?")) { $(this)

嗨,我有这些代码来删除一个表行,我的问题是,当我删除一个在数字之间的行时,例如我有4行,我删除了第2行,行的编号将类似于1,3,4。。但我需要它是1,2,3,我怎样才能做到这一点?谢谢你的帮助

下面是我如何动态添加表的

    $('#mhTable').on('click', '.DeleteRow', function() 
    {
        if(confirm("Are you sure you want to delete this?")) {
        $(this).closest('tr').remove();
        count --;
        }
        else {
            return false;
        }
    });
var rowCount=$('mhTable>tbody>tr')。长度;
变量计数=行计数+1;
var host=window.location.protocol++“//”+window.location.host++“/”+“\files/Icons/delete.png”;
$('#mhAddRow')。单击(函数(e)
{
美元(“#mhTable tr:last”)。之后(“”
+ '      '
+ '   '
+ '    '
+ '   '
+ '    '
+ '    '
+ '    '
+ '   '
+ '   '
+ '    '
+ '     ');
$.post('mis.php/new_development_request/loadView_newDevelopmentRequest',{counter:count});
计数++;
});

首先删除行,然后使用$更新其他tr。每个功能

看一看小提琴,得到你的结果:

$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
$(this).closest('tr').remove();
$(“.row id”)。每个(函数(i){
$(本).text(i+1);
}); 
});     
});

1.
一排
删除
2.
第2排
删除
3.
第3排
删除
4.
第4排
删除

编号方式和位置?先生,我已经更新了我的帖子,我已经把代码放在如何添加表行上了。如果这就是我正在做的方法呢?你的解决方案可行吗?是的。可能的根据您的表格结构,这里还有一把小提琴:我想实现的是,即使是流程、图片等的名称也将重新编号为HI,先生。。如果要删除从数据库中删除的行,该怎么办。也有可能吗?很抱歉,我真的需要一些帮助。@Dale,是的,可能。您可以使用jqueryajax实现这一点。
var rowCount = $('#mhTable >tbody >tr').length;
var count = rowCount + 1;
var host = window.location.protocol + "//" + window.location.host + "/" + "\files/Icons/delete.png";
    $('#mhAddRow').click(function(e) 
    {
        $("#mhTable tr:last").after('<tr id="row' + count + '">'
        + '<td> <sup> <img class="DeleteRow" style="cursor:pointer;" id="rowDelete" name="rowDelete" height="7" width="7" src="'+host+'"> </sup> <input type="text" id="rowsID'+count+'" name="rows['+count+']" style="width:73%;text-align:center;" value="'+count+'" readOnly="readonly"> </input> </td>'

        + '<td> <input type="text" style="width:98%;" id="process" class="process" name="process['+count+']" value=""> </input> </td>'

        + '<td> <input type="text" style="width:96%;" id="PIC" class="PIC" name="PIC['+count+']" value="" > </input> </td> '

        + '<td> <input type="text" style="width:95%;text-align:right;" id="prev" class="prev" name="prev['+count+']" onkeyup="ManhourSaving();totalmhPrevious();ManhourSavingRatio();mhInMinutes();savedMHyearly();costAnnual()" onkeypress="return isNumberKey(event)" maxlength="5" value="" ></input> </td> '

        + '<td> <input type="text" style="width:95%;text-align:right;" id="expect" class="expect" name="expect['+count+']" class="expected" onkeyup="ManhourSaving();totalmhExpected();ManhourSavingRatio();mhInMinutes();savedMHyearly();costAnnual()" onkeypress="return isNumberKey(event)" maxlength="5" value="" > </input> </td> '

        + '<td> <input type="text" style="width:96%;text-align:right;" id="mhSavings" class="mhSavings" name="mhSavings['+count+']" readOnly="readonly" value="0.00" > </input> </td> '

        + '<td> <input  type="text" style="width:95%;text-align:right;" id="ratio" class="ratio" name="ratio['+count+']" readOnly="readonly" value="0.00" > </input> </td> '

        + '<td> <input type="text" style="width:95%;text-align:right;" id="PaperReducPrev" class="PaperReducPrev" name="PaperReducPrev['+count+']"onkeyup="PaperReductionPrevious();PaperReduction();PaperReductionRatio();totalPaperReduced();paperReductionyearly();costSheet()" onkeypress="return isNumberKey(event)" maxlength="5" value="" > </input> </td>'

        + '<td> <input type="text" style="width:95%;text-align:right;" id="PaperReducExpect" class="PaperReducExpect" name="PaperReducExpect['+count+']" onkeyup="PaperReductionExpected();PaperReduction();PaperReductionRatio();totalPaperReduced();paperReductionyearly();costSheet()" onkeypress="return isNumberKey(event)" maxlength="5" value="" > </input> </td>'

        + '<td> <input type="text" style="width:96%;text-align:right;" id="paperReduced" class="paperReduced" name="paperReduced['+count+']" readOnly="readonly" value="0"> </input> </td> '

        + '<td> <input type="text" style="width:95%;text-align:right;" id="PaperReducRatio" class="PaperReducRatio" name="paperReducRatio['+count+']" readOnly="readonly" value="0.00" > </input>  </td> ');

        $.post('mis.php/new_development_request/loadView_newDevelopmentRequest', {counter: count});
        count++;
    });