点击按钮 添加一行表格(字符串拼接)

<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 + '&nbsp;&nbsp;' + 'cell1' + '<td>row' + i + '&nbsp;&nbsp;' + 'cell2' + '</td>' + '</td>' + '</tr>'
    document.getElementById('insert_Row').appendChild(tr)
  }

 

posted @ 2022-03-27 08:58  生活在北极的企鹅  阅读(105)  评论(0编辑  收藏  举报