Suppression ligne tableau
Bonjour ,
Un tableau se construit ligne par ligne .
Ensuite la suppression bloque ..
html :
Code:
1 2 3 4 5
| <h3>Liste des clients</h3>
<table>
<th>Nom</th><th>Prénom</th><th>Téléphone</th>
</table>
<input type=button value="Insérer une ligne" id=insert /> |
Jq :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| // Ajout ligne tableau
$("#insert").bind ("click", function (){
var html ="";
html += "<tr>";
html += "<td><input type=text /></td>";
html += "<td><input type=text /></td>";
html += "<td><input type=text /></td>";
html += "<td><input type=button value=Supprimer id=remove /></td>";
html += "</tr>";
$("table").append (html);
$("table").find("tr:last").find ("input[type=text]:first").focus();
});
// Suppression ligne tableau
$("#remove").live ("click", function (){
var $tr = $(this).parents ("tr");
var id = $tr.attr ("id");
$tr.remove ();
}); |
:mrgreen: