Javascript 向表中添加行会更改选择索引吗?
我正在使用包含Javascript 向表中添加行会更改选择索引吗?,javascript,html,dom,ecmascript-6,Javascript,Html,Dom,Ecmascript 6,我正在使用包含元素的java脚本向表中添加行,每次向表中添加新行时,所选索引都会更改 我把它分解成简单的形式,试图重现正在发生的事情 让currentRows=0; 函数addRow(){ 让行= ` 1. 2. 3. `; 控制台日志(行); document.getElementById(“myTable body”).innerHTML+=行; currentRows=currentRows+1; } 添加行 尝试使用createElement和appendChild方法 让curr
元素的java脚本向表中添加行,每次向表中添加新行时,所选索引都会更改
我把它分解成简单的形式,试图重现正在发生的事情
让currentRows=0;
函数addRow(){
让行=
`
1.
2.
3.
`;
控制台日志(行);
document.getElementById(“myTable body”).innerHTML+=行;
currentRows=currentRows+1;
}
添加行
尝试使用createElement
和appendChild
方法
让currentRows=0;
函数addRow(){
var tr=document.createElement('tr');
tr.setAttribute('id','row-'+currentRows);
tr.innerHTML=
`
1.
2.
3.
`;
document.getElementById(“MyTableBody”).appendChild(tr);
currentRows=currentRows+1;
}
添加行
尝试使用createElement
和appendChild
方法
让currentRows=0;
函数addRow(){
var tr=document.createElement('tr');
tr.setAttribute('id','row-'+currentRows);
tr.innerHTML=
`
1.
2.
3.
`;
document.getElementById(“MyTableBody”).appendChild(tr);
currentRows=currentRows+1;
}
添加行