add rows to table with JavaScript

后端 未结 2 569
既然无缘
既然无缘 2021-01-29 09:41

I am trying to use JavaScript or ASP C# to add rows to a table in form when the user clicks the add row button. I have working code in JavaScript. I want to add the rows with te

2条回答
  •  Happy的楠姐
    2021-01-29 10:36

    function addrow() {
        var myTable = document.querySelector('#tbl');
        var row = myTable .insertRow(0);
        var cell1 = row.insertCell(0);
        cell1.innerHTML = 'My first cell';
    
        // and so on for other cells
    }
    

    p.s. please add "" to all your HTML attributes values. For example

    提交回复
    热议问题