1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <script type="text/javascript">
function ajouteChamps(ici) {
var newTR = document.createElement("tr"); // crée un élément tr
ici.appendChild(newTR); // ajoute le tr au tbody
var newTD = document.createElement("td"); // crée un élément td
newTR.appendChild(newTD); // ajoute le td au tr
//newTD.appendChild(document.createTextNode('toto')); pour ajouter du texte
var newINPUT = document.createElement("input"); // crée l'input
newINPUT.setAttribute('type','text'); // ajoute ses attributs
newTD.appendChild(newINPUT); // ajoute l'input au td
}
</script>
<input type="submit" name="ajout" onClick="ajouteChamps(document.getElementById('maTable'))" value="Ajoute un champ"/>
<table>
<tbody id="maTable">
<tr>
<td><input type="text" name="val"/></td>
</tr>
</tbody>
</table> |