Bonjour,

J'ai une modal popup jquery, avec une table de composant.
Sur chaque ligne j'ai un bouton supprimer. donc si je veux que mon bouton fonctionne
j'ai fais:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
  function EditionElem(RowID) {
            $.ajax({
                type: "POST",
                url: "Lst_Element.aspx/GetElement",
                data: '{"IdElem":' + RowID + ',"PageEnCours":"' + document.location.href.toString() + '"}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    if (msg.d != null) {
                        $('#MPEditElem').dialog('option', 'title', msg.d.titre);
                        BuildTable(msg.d);
                        BuildFonctionCompos();
                        $("#MPEditElem").dialog("open");
                    }
                    else {
                        var Ret = new function () {
                            this.Reussi = false;
                            this.Msg = "Problème récupération élément";
                        }
                        AfficheMsgRetour(Ret)
                    }
                },
                error: function () {
                    alert('Erreur récupération élément!');
                }
            });
        }
 
        function BuildTable(msg) {
            var table = '<table>';
            if (msg.Id == "-1") {
                table += '<tr><td class="FormLib">Libellé</td><td class="FormCell"><input type="text" id="txtNom" /><br /><label class="error" for="txtNom" id="Nom_error">Champs Libellé obligatoire.</label></td></tr>';
                table += '<tr><td class="FormLib">Dimension</td><td class="FormCell"><input type="text" id="txtDim" /></td></tr>';
                table += '<tr><td class="FormLib" colspan="2" align="right"><button id="btnEnrElem">Valider</button></td></tr>';
                table += '<input type="hidden" id="hidId" value="' + msg.Id + '"/></table>';
                table += '<div id="DivCompos"><br/>Liste des composants:';
                table += '<table id="tblCompos" width="100%"><tr class="Entete"><td>Composant</td><td>Nombre</td><td>Définit<br />couleur</td><td></td></tr><tbody>';
                table += '</tbody><tr class="Entete2"><td><br /><select id="lstCompo"></select><br /><br /><label class="error" id="Compo_error">Sélectionnez un composant.</label></td>';
                table += '<td><br /><input type="text" id="txtNb" maxlength="3" style="width: 40px; text-align: right;" /><br /><br /><label class="error" for="txtNb" id="Nb_error"></label></td>';
                table += '<td><input type="checkbox" id="chkColor" /></td><td><img src="/Images/add.png" alt="Ajouter" id="AddCompo" /></td></tr>';
                table += '</table></div>';
            }
            else {
                table += '<tr><td class="FormLib">Libellé</td><td class="FormCell"><input type="text" id="txtNom" value="' + msg.Libelle + '"/><br /><label class="error" for="txtNom" id="Nom_error">Champs Libellé obligatoire.</label></td></tr>';
                table += '<tr><td class="FormLib">Dimension</td><td class="FormCell"><input type="text" id="txtDim" value="' + msg.Dimension + '"/></td></tr>';
                table += '<tr><td class="FormLib" colspan="2" align="right"><button id="btnEnrElem" >Valider</button></td></tr>';
                table += '<input type="hidden" id="hidId" value="' + msg.Id + '"/></table>';
 
                //Liste des composants
                table += '<div id="DivCompos"><br/>Liste des composants:';
                table += '<table id="tblCompos" width="100%"><tr class="Entete"><td>Composant</td><td>Nombre</td><td>Définit<br />couleur</td><td></td></tr><tbody>';
                for (var post in msg.Compos) {
                    table += AddComposTbl(msg.Compos[post].IdCompo, msg.Compos[post].LibCompo, msg.Compos[post].NbCompo, msg.Compos[post].DefCoul);
                }
 
                //Ajout composant
                table += '</tbody><tr class="Entete2"><td><br /><select id="lstCompo"></select><br /><br /><label class="error" id="Compo_error">Sélectionnez un composant.</label></td>';
                table += '<td><br /><input type="text" id="txtNb" maxlength="3" style="width: 40px; text-align: right;" /><br /><br /><label class="error" for="txtNb" id="Nb_error"></label></td>';
                table += '<td><input type="checkbox" id="chkColor" /></td><td><img src="/Images/add.png" alt="Ajouter" id="AddCompo" /></td></tr>';
                table += '</table></div>';
            }
 
            $('#ContenuEditElem').html(table);
        };
 
        function AddComposTbl(IdCompo, LibCompo, NbCompo, DefCoul) {
            var row = '<tr id=' + IdCompo + '><td align="left">' + LibCompo;
            row += '</td><td>' + NbCompo + '</td>';
            row += '<td><div id="Color" ' + (DefCoul === true ? 'class="actif">' : '>');
            row += '</div></td><td><img src="/Images/suppr.png" alt="Supprimer" class="JQDeleteCompo"/></td></tr>';
            return row;
        }
 
        function BuildFonctionCompos() {
            $('.error').hide();
 
            $('button#btnEnrElem').button().click(function () {
                $('.error').hide();
                ValidationElem();
            });
 
            //Charger la liste des composants
            $.ajax({
                type: "POST",
                url: "Lst_Element.aspx/GetComposants",
                data: '{"PageEnCours":"' + document.location.href.toString() + '"}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    $('#lstCompo').append($('<option>', { value: "-1", text: "Sélectionnez un composant" }));
                    if (msg.d != null) {
                        $.each(msg.d, function (i, item) {
                            if (msg.d != null) {
                                $('#lstCompo').append($('<option>', { value: item.IdCompo, text: item.Libelle }));
                            }
                        });
                    }
                },
                error: function () {
                    alert('oups');
                }
            });
 
            //Mapper l'ajout de composant
            AddComposant();
 
            if ($('#hidId').val() == "-1") {
                $('div#DivCompos').hide();
            }
            else {
 
                //Mapper la suppression de composant déjà présent
                DelComposant();
            }
        }
function AddComposant() {
            $("#AddCompo").click(function () {
                $('.error').hide();
 
                var Compos = $("#lstCompo").val();
                if (Compos == "-1") {
                    $("#Compo_error").show();
                    return false;
                }
 
                var CtrlNb = $('#txtNb');
                var Nb = CtrlNb.val();
                if (Nb == "") {
                    $("#Nb_error").text("Champs Nombre obligatoire.");
                    $("#Nb_error").show();
                    CtrlNb.focus();
                    return false;
                }
 
                if (isNaN(Nb)) {
                    $("#Nb_error").text("Numérique uniquement.");
                    $("#Nb_error").show();
                    CtrlNb.focus();
                    return false;
                }
 
                var myData = {};
                myData.IdElem = $('#hidId').val();
                myData.IdCompos = Compos;
                myData.Nb = Nb
                myData.DefColor = $('#chkColor').is(':checked'); ;
                myData.PageEnCours = document.location.href;
 
                $.ajax({
                    type: "POST",
                    url: "Lst_Element.aspx/AddCompo",
                    data: "{MesDonnees:" + JSON.stringify(myData) + "}",
                    contentType: 'application/json; charset=utf-8',
                    dataType: "json",
                    success: function (msg) {
                        AfficheMsgRetour(msg.d)
                        if (msg.d.Reussi == true) {
                            //Ajouter manuellement la ligne
                            $('#tblCompos > tbody:first').append(AddComposTbl(myData.IdCompos, $("#lstCompo :selected").text(), myData.Nb, myData.DefColor));
                            //Remapper la suppression
                            DelComposant();
                        }
                    },
                    error: function () {
                        var Ret = new function () {
                            this.Reussi = false;
                            this.Msg = "Erreur accès ajout composant.";
                        }
                        AfficheMsgRetour(Ret)
                    }
                });
 
                return false;
            });
        }
 
 function DelComposant() {
            $(".JQDeleteCompo").click(function () {
                $('.error').hide();
 
                var $tr = $(this).parents('tr:eq(0)'), id = $tr.attr('id');
                if (confirm("Confirmez-vous la suppression ?")) {
                    $.ajax({
                        type: "POST",
                        url: "Lst_Element.aspx/DelCompo",
                        data: '{"IdElem":' + $('#hidId').val() + ',"IdCompo":' + id + ',"PageEnCours":"' + document.location.href.toString() + '"}',
                        contentType: 'application/json; charset=utf-8',
                        dataType: "json",
                        success: function (msg) {
                            AfficheMsgRetour(msg.d);
                            if (msg.d.Reussi == true) {
                                $("#" + id).hide();
                            }
                        },
                        error: function () {
                            var Ret = new function () {
                                this.Reussi = false;
                                this.Msg = "Erreur accès suppression";
                            }
                            AfficheMsgRetour(Ret)
                        }
                    });
                }
                return false;
            });
        }
Le problème est que si j'ajoute 3 lignes ... quand je clique sur supprimer la première, ça s'exécute 3 fois
J'ai fait la fonction DelComposant car je l'appelle aussi lors du 1ere affichage pour mapper l'evt de suppression sur les lignes déjà existante.

Comment faire pour appliquer mon ajout evt suppression qu'à mon nouveau bouton et pas à tous et éviter que ça multi-déclanche ma suppression?