Supprimer les TR d'une TABLE générée dynamiquement
Bonjour.
J'arrive très bien à générer une ligne dans mon tableau, mais pas moyen de la supprimer.
Avez vous une idée ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<body>
<script type="text/javascript">
<!-- Ajouter un champ pour les retours -->
var count = 0;
function one_more_ligne ()
{
count++;
var element = document.getElementById("table_2");
var tr = document.createElement("tr");
var td_1 = document.createElement("td");
var td_2 = document.createElement("td");
var td_3 = document.createElement("td");
var inp1 = document.createElement("input");
var inp2 = document.createElement("input");
var inp3 = document.createElement('input');
tr.id = "tr_"+count;
inp1.name = "retour_commande";
inp2.name = "retour_poids";
inp1.type = "text";
inp1.id = "retour_commande_"+count;
inp2.type = "text";
inp2.id = "retour_poids_"+count;
inp3.type = "button";
inp3.value = "Effacer la ligne";
inp3.id = +count;
// On enlève sur le click du bouton
inp3.onclick = function()
{
// code ici pour la suppression
}
td_1.appendChild(inp1);
td_2.appendChild(inp2);
td_3.appendChild(inp3);
tr.appendChild(td_1);
tr.appendChild(td_2);
tr.appendChild(td_3);
byId("table_2").getElementsByTagName('tbody')[0].appendChild(tr);
}
function byId(elmId)
{
var elm = document.getElementById(elmId);
if(elm==null)
elm = document.getElementsByName(elmId)[0];
return elm;
}
</script>
<input type="button" onclick="one_more_ligne()" value="Ajouter un retour">
<br>
<table cellspacing="0" cellpadding="0" style="width: 50%;" class="table" name="table_2" id="table_2" border="1">
<thead>
<tr>
<th>Commande(s) retournee(s)</th>
<th>Poids du colis retournee</th>
<th>Effacer la ligne</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" name="retour_commande" id="retour_commande_1"></td>
<td><input type="text" name="retour_poids" id="retour_poids_1"></td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html> |
Merci et bon DEV