Bonjour,
Sur mon projet, je dois gérer un tableau HTML dynamique qui peut avoir plusieurs (0/1000) éléments dans celui ci.
Voilà un exemple HTML :
Code html : 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 <div class="ListeLicence"> <table class="table table-striped"> <tbody><tr id="0"> <th>Logiciel</th> <th>Licence</th> <th>Quantité</th> <th>Prix total</th> <th>Autre</th> </tr> <tr id="1" qt="10"> <td>Skype</td> <td>1 mois</td> <td>10</td> <td>800</td> <td> <i id="1" class="glyphicon glyphicon-trash deleteSoft"></i></td> </tr> <tr id="1" qt="10"> <td>Skype</td> <td>1 mois</td> <td>10</td> <td>800</td> <td> <i id="1" class="glyphicon glyphicon-trash deleteSoft"></i></td> </tr> <tr id="1" qt="10"> <td>Skype</td> <td>1 mois</td> <td>10</td> <td>800</td> <td> <i id="1" class="glyphicon glyphicon-trash deleteSoft"></i></td> </tr> </tbody> </table> <button type="button" class='btn btn-success btn-add-li'>Ajouter</button> </div>
Et donc, à l'aide d'un each, je parcoure mes éléments :
Et je ne comprend pas, voilà le résultat de mon console.log :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 $('.btn-add-li').click(function(){ var dispo = new Array(); var qt = new Array(); f = 0; id = $('.table').attr('user-id'); $('.table-striped tbody tr').each(function() { if($(this).attr('id') != 0){ dispo.push($(this).attr('id')); } }); console.log(dispo); console.log('ici'); });
http://hpics.li/b7c540a
En gros, j'exécute une fois au clique, je me retrouve avec la fonction exécuté trois fois,trois tableau de mes trois éléments, plus j'ai d'éléments, plus ma fonction est exécuté, 20 éléments dans mon tableau HTML, au clique sur mon bouton, j'ai 20 tableau de 20 éléments chacun dans ma console...
Si quelqu'un a une explication, car la, je ne comprend pas.
Merci d'avance.
Partager