Javascript 无法使用索引号在两行中间添加行

Javascript 无法使用索引号在两行中间添加行,javascript,html,Javascript,Html,我已经动态地创建了一个表,现在我想在已经存在的两行之间添加一行,我正在下面的代码中尝试,但它不起作用 var newRow = '<tr id="' + RowCountDoctorVisit + '">' + '<td ><a href="javascript:void(0);" onclick="removeRowDoctor(' + RowCountDoctorVisit + ');">&

我已经动态地创建了一个表,现在我想在已经存在的两行之间添加一行,我正在下面的代码中尝试,但它不起作用

 var newRow = '<tr id="' + RowCountDoctorVisit + '">' +
                                '<td ><a href="javascript:void(0);" onclick="removeRowDoctor(' + RowCountDoctorVisit + ');"><i class="fa fa-trash"></i></a>&nbsp;' +
                                   '<a href="javascript:void(0);" onclick="EditDoctorRow(' + RowCountDoctorVisit + ');"><i class="fa fa-edit"></i></a>' +
                                '</td>' +
                                '<td class="column" data-label="DoctorName">' + DoctorName +
                               '</td><td style="display:none;" data-label="DoctorID">' + DoctorID +
                               '<td class="column" data-label="Visit Type">' + VisitType +
                               '</td><td style="display:none;" data-label="Visit Type ID">' + VisitTypeID +
                                '<td class="column" data-label="Room Group Name">' + RoomGroupName +
                               '</td><td style="display:none;" data-label="Room Group ID">' + RoomGroupID +
                               '</td><td class="column" data-label="Rate">' + Rate +
                               '</td><td class="column" data-label="Unit">' + Unit +
                               '</td><td class="column" data-label="Amount">' + Amount +
                               '</tr>'

document.getElementById("DoctorIndex").value contains index number
    $('table#DoctorVisit > tbody > tr:eq(' + document.getElementById("DoctorIndex").value + ')').after(newRow);
var newRow=''+
' ' +
'' +
'' +
''+博士名+
''+博士+
''+访问类型+
''+访问类型ID+
''+RoomGroupName+
''+房间组ID+
''+费率+
''+单位+
''+金额+
''
document.getElementById(“DoctorIndex”)。值包含索引号
$('table#DoctorVisit>tbody>tr:eq('+document.getElementById(“DoctorIndex”).value+'))。在(newRow)之后;

我尝试了类似的方法,效果很好,但如果我想使用newRow变量添加整行

var tbl = document.getElementById("DoctorVisit");
            var indexno = document.getElementById("DoctorIndex").value;
            var row = tbl.insertRow(indexno);
            row.id = RowCountDoctorVisit;
        var cell1 = row.insertCell(0);
        cell1.className = 'column';
        var cell2 = row.insertCell(1);
        cell2.className = 'column';
        var cell3 = row.insertCell(2);
        cell3.className = 'dynamicallyHiddenRow';
        var cell4 = row.insertCell(3);
        cell4.className = 'column';
        var cell5 = row.insertCell(4);
        cell5.className = 'dynamicallyHiddenRow';
        var cell6 = row.insertCell(5);
        cell6.className = 'column';
        var cell7 = row.insertCell(6);
        cell7.className = 'dynamicallyHiddenRow';
        var cell8 = row.insertCell(7);
        cell8.className = 'column';
        var cell9 = row.insertCell(8);
        cell9.className = 'column';
        var cell10 = row.insertCell(9);
        cell10.className = 'column';
        cell1.innerHTML = '<a href="javascript:void(0);" onclick="removeRowDoctor(' + RowCountDoctorVisit + ');"><i class="fa fa-trash"></i></a>&nbsp;<a href="javascript:void(0);" onclick="EditDoctorRow(' + RowCountDoctorVisit + ');"><i class="fa fa-edit"></i></a>';
        cell2.innerHTML = DoctorName;
        cell3.innerHTML = DoctorID;
        cell4.innerHTML = VisitType;
        cell5.innerHTML = VisitTypeID;
        cell6.innerHTML = RoomGroupName;
        cell7.innerHTML = RoomGroupID;
        cell8.innerHTML = Rate;
        cell9.innerHTML = Unit;
        cell10.innerHTML = Amount;
var tbl=document.getElementById(“DoctorVisit”);
var indexno=document.getElementById(“DoctorIndex”).value;
变量行=tbl.insertRow(indexno);
row.id=RowCountDoctorVisit;
var cell1=行插入单元格(0);
cell1.className='列';
var cell2=行插入单元格(1);
cell2.className='列';
var cell3=行插入单元格(2);
cell3.className='dynamicallyHiddenRow';
var cell4=行插入单元格(3);
cell4.className=‘column’;
var cell5=行插入单元格(4);
cell5.className='dynamicallyHiddenRow';
var cell6=行插入单元格(5);
cell6.className=‘column’;
var cell7=行插入单元格(6);
cell7.className='dynamicallyHiddenRow';
var cell8=行插入单元格(7);
cell8.className=‘column’;
var cell9=行插入单元格(8);
cell9.className=‘column’;
var cell10=行插入单元格(9);
cell10.className=‘column’;
cell1.innerHTML='';
cell2.innerHTML=DoctorName;
cell3.innerHTML=DoctorID;
cell4.innerHTML=VisitType;
cell5.innerHTML=访问类型ID;
cell6.innerHTML=RoomGroupName;
cell7.innerHTML=RoomGroupID;
cell8.innerHTML=速率;
cell9.innerHTML=单位;
cell10.innerHTML=金额;

我尝试了类似的方法,效果很好,但如果我想使用newRow变量添加整行

var tbl = document.getElementById("DoctorVisit");
            var indexno = document.getElementById("DoctorIndex").value;
            var row = tbl.insertRow(indexno);
            row.id = RowCountDoctorVisit;
        var cell1 = row.insertCell(0);
        cell1.className = 'column';
        var cell2 = row.insertCell(1);
        cell2.className = 'column';
        var cell3 = row.insertCell(2);
        cell3.className = 'dynamicallyHiddenRow';
        var cell4 = row.insertCell(3);
        cell4.className = 'column';
        var cell5 = row.insertCell(4);
        cell5.className = 'dynamicallyHiddenRow';
        var cell6 = row.insertCell(5);
        cell6.className = 'column';
        var cell7 = row.insertCell(6);
        cell7.className = 'dynamicallyHiddenRow';
        var cell8 = row.insertCell(7);
        cell8.className = 'column';
        var cell9 = row.insertCell(8);
        cell9.className = 'column';
        var cell10 = row.insertCell(9);
        cell10.className = 'column';
        cell1.innerHTML = '<a href="javascript:void(0);" onclick="removeRowDoctor(' + RowCountDoctorVisit + ');"><i class="fa fa-trash"></i></a>&nbsp;<a href="javascript:void(0);" onclick="EditDoctorRow(' + RowCountDoctorVisit + ');"><i class="fa fa-edit"></i></a>';
        cell2.innerHTML = DoctorName;
        cell3.innerHTML = DoctorID;
        cell4.innerHTML = VisitType;
        cell5.innerHTML = VisitTypeID;
        cell6.innerHTML = RoomGroupName;
        cell7.innerHTML = RoomGroupID;
        cell8.innerHTML = Rate;
        cell9.innerHTML = Unit;
        cell10.innerHTML = Amount;
var tbl=document.getElementById(“DoctorVisit”);
var indexno=document.getElementById(“DoctorIndex”).value;
变量行=tbl.insertRow(indexno);
row.id=RowCountDoctorVisit;
var cell1=行插入单元格(0);
cell1.className='列';
var cell2=行插入单元格(1);
cell2.className='列';
var cell3=行插入单元格(2);
cell3.className='dynamicallyHiddenRow';
var cell4=行插入单元格(3);
cell4.className=‘column’;
var cell5=行插入单元格(4);
cell5.className='dynamicallyHiddenRow';
var cell6=行插入单元格(5);
cell6.className=‘column’;
var cell7=行插入单元格(6);
cell7.className='dynamicallyHiddenRow';
var cell8=行插入单元格(7);
cell8.className=‘column’;
var cell9=行插入单元格(8);
cell9.className=‘column’;
var cell10=行插入单元格(9);
cell10.className=‘column’;
cell1.innerHTML='';
cell2.innerHTML=DoctorName;
cell3.innerHTML=DoctorID;
cell4.innerHTML=VisitType;
cell5.innerHTML=访问类型ID;
cell6.innerHTML=RoomGroupName;
cell7.innerHTML=RoomGroupID;
cell8.innerHTML=速率;
cell9.innerHTML=单位;
cell10.innerHTML=金额;

那么会发生什么?错误?什么是新行?您是否检查了
document.getElementById(“DoctorIndex”).value
value?我已经编辑了newRow=我要添加数据的行和
document.getElementById(“DoctorIndex”)。value
包含索引,不知道会发生什么?错误?什么是新行?您是否检查了
document.getElementById(“DoctorIndex”).value
value?我已编辑了newRow=我要添加数据的行和
document.getElementById(“DoctorIndex”)。value
包含索引号