动态表的数字对齐

时间:2018-04-16 04:03:06

标签: php jquery html

我有一个充满ajax请求的动态表:

我已使用jquery代码合并了相同的值单元格:

$(document).ready(function(){
$(function() {  
    function groupTable($rows, startIndex, total){
        if (total === 0){
            return;
        }
        var i , currentIndex = startIndex, count=1, lst=[];
        var tds = $rows.find('td:eq('+ currentIndex +')');
        var ctrl = $(tds[0]);
        lst.push($rows[0]);
        for (i=1;i<=tds.length;i++){
            if (ctrl.attr("id") ==  $(tds[i]).attr("id")){
                count++;
                $(tds[i]).addClass('deleted');
                lst.push($rows[i]);
            }
            else{
                if (count>1){
                    ctrl.attr('rowspan',count);
                    groupTable($(lst),startIndex+1,total-1)
                }
                count=1;
                lst = [];
                ctrl=$(tds[i]);
                lst.push($rows[i]);
            }
        }
    }
    groupTable($('#myTable tr:has(td)'),0,15);
    $('#myTable .deleted').remove();
});
$('#myTable tbody tr#p').each(function (idx) {
    $(this).children("td:eq(0)").html(idx + 1);
});

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-striped border-top table-bordered" id="myTable"> 
    <thead>
        <tr id="th1">
            <th>Num</th>
            <th>A</th>
            <th>B</th>
            <th>Third</th>
            <th colspan="3">C</th>
            <th colspan="3">D</th>
            <th colspan="2">E</th>

            <th>SUM</th>
            <th>-</th>
        </tr>
        <tr id="th2">
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th>C1</th>
            <th>C2</th>
            <th>C3</th>
            <th>D1</th>
            <th>D2</th>
            <th>D2</th>
            <th>SUM C</th>
            <th>SUM D</th>
            <th></th>
            <th></th>
        </tr>
    </thead>
    <tbody id="details_view">

    </tbody>
</table>

接下来,我想为每一行添加数字,我使用以下代码: 但问题是合并的行也得到一个数字,我附加了结果:

RESULT IMAGE

图片链接:See result 那我怎么解决这个问题?

0 个答案:

没有答案