点击按钮 添加一行表格(字符串拼接)
<table id="insert_Row" border="1"> <tr> <td>Row1 cell1</td> <td>Row1 cell2</td> </tr> <tr> <td>Row2 cell1</td> <td>Row2 cell2</td> </tr> </table><br> <input type="button" onclick="insert_Row()" value="Insert row">
这里是js文件
let i = 2; function insert_Row() { i++; let tr = document.createElement('tr') tr.innerHTML = '<tr>' + '<td>row' + i + ' ' + 'cell1' + '<td>row' + i + ' ' + 'cell2' + '</td>' + '</td>' + '</tr>' document.getElementById('insert_Row').appendChild(tr) }