Conforme mostrado abaixo:
Copie o código do código da seguinte forma:
//Adiciona linhas dinamicamente
função addRow(){
var tabela = document.getElementById("tableID");
var newRow = table.insertRow(); //Cria uma nova linha
var newCell1 = newRow.insertCell();
newCell.innerHTML = ""; //Conteúdo dentro da célula
newCell.setAttribute("align","center"); //Definir a posição
}
//Exclui linhas dinamicamente
função deleteRow(){
var rowIndex = event.srcElement.parentElement.parentElement.rowIndex;
var estilos = document.getElementById("tableID");
estilos.deleteRow(rowIndex);
}
<html>
<cabeça>
<título></título>
</head>
<corpo>
<table id="testTbl" border=1>
<tr>
<td>
Nome do produto
</td>
<td>
Quantidade do produto
</td>
<td>
Preço unitário do produto
</td>
</tr>
<tr>
<td>
<selecione nome="a">
<option value="Eletrônico">Eletrônico</option>
<option value="Eletrodomésticos">Eletrodomésticos</option>
</select></td>
<td>
<input type="text" nome="b">
</td>
<td>
<input type="text" nome="c">
</td>
</td>
</tabela>
<input type="button" name="Submit2" value="Adicionar" onclick="addRow()">
<roteiro>
função addRow(){
//adiciona linha
var newTr = testTbl.insertRow();
//adiciona coluna
var novoTd0 = newTr.insertCell();
var novoTd1 = newTr.insertCell();
var novoTd2 = newTr.insertCell();
var novoTd3 = newTr.insertCell();
//Definir conteúdo e atributos da coluna
newTd0.innerText = document.all("a").options[document.all("a").selectedIndex].text;
newTd1.innerText = document.all("b").valor;
newTd2.innerText = document.all("c").valor;
newTd3.innerHTML= '<input type="button" name="del" value="Delete" onclick="del(this)">';
}
funçãodel(o)
{
var t=document.getElementById('testTbl');
t.deleteRow(o.parentNode.parentNode.rowIndex)
}
</script>
</body>
</html>