ID | Champ 1 | Champ 2 | Champ 3 | Champ 4 |
1 | 11 | 12 | 13 | 14 |
2 | 22 | 26 | 28 | 27 |
Total |
<table id="mytable" border="1" width="37%">
<thead>
<tr>
<td width="63" >ID</td>
<td width="68" >字段1</td>
<td width="62" >字段2</td>
<td width="75" >字段3</td>
<td>字段4</td>
</tr>
</thead>
<tr>
<td>1</td>
<td width="63" >11</td>
<td width="68" >12</td>
<td width="62" >13</td>
<td width="75" >14</td>
</tr>
<tr>
<td>2</td>
<td width="63" >22</td>
<td width="68" >26</td>
<td width="62" >28</td>
<td width="75" >27</td>
</tr>
<tr id="totalRow">
<td>合计</td>
<td width="63" ></td>
<td width="68" ></td>
<td width="62" ></td>
<td width="75" ></td>
</tr>
</table>
Je viens d'apprendre le front-end. Est-ce que quelqu'un sait comment utiliser JQ pour additionner automatiquement chaque colonne au total
Il existe de nombreux tableaux de ce type sur une seule page qui doivent être comptés Q_Q
Faites attention à la structure HTML, vous avez écrit
thead
却没有写body
, modifiez-la comme suit :Parmi eux,
thead
和tbody
和tfoot
都分开,thead
为表头不遍历,tbody
为遍历部分,tfoot
est la partie récapitulative pour faciliter l'utilisation du sélecteur jQuery.Mise à jour
Voici quelques points de connaissances :
new Array()
Construire un nouveau tableau.fill()
remplir le tableauUtilisation du sélecteur
:not()
和:first-child
Ajoutez
+
devant une chaîne ou un nombre pour forcer sa conversion en nombreUtilisation d'un opérateur d'affectation
+=
J'espère que vous pourrez comprendre le
code HTML
code js
jquery chacun parcourt chaque colonne, les additionne et les place dans la dernière ligne