<table data-toggle="table" data-pagination="true" data-search="true" data-show-columns="true" data-show-pagination-switch="true" data-show-refresh="true" data-key-events="true" data-show-toggle="true" data-resizable="true" data-cookie="true" data-cookie-id-table="saveId" data-show-export="true" data-click-to-select="true" data-toolbar="#toolbar">
<thead>
<tr>
<th>Name</th>
<th>Birthday</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<?php foreach($people as $person) { ?>
<tr>
<td><?php echo $person["name"]; ?></td>
<td id="birthday"><?=$person["birthday"] ?></td>
<td><?php echo $person["address"]; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
À partir de cette table, je voudrais obtenir une valeur d'anniversaire de la boucle.
Comment puis-je obtenir chaque valeur dans jQuery ?
L'ID doit être UNIQUE. Faites-en une classe
$(".birthday").each(function() { // or more specific: $("tbody tr td.birthday")
console.log($(this).text())
});
// or
$(".birthday").each(function() {
const bDay = $(this).text()
const name = $(this).prev().text();
console.log(name,bDay)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table data-toggle="table" data-pagination="true" data-search="true" data-show-columns="true" data-show-pagination-switch="true" data-show-refresh="true" data-key-events="true" data-show-toggle="true" data-resizable="true" data-cookie="true" data-cookie-id-table="saveId"
data-show-export="true" data-click-to-select="true" data-toolbar="#toolbar">
<thead>
<tr>
<th>Name</th>
<th>Birthday</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<tr>
<td>Fred</td>
<td class="birthday">25 May 1990</td>
<td>Road 2</td>
</tr>
<tr>
<td>Joe</td>
<td class="birthday">5 June 1980</td>
<td>Road 1</td>
</tr>
</tbody>
</table>
Cet article est collecté sur Internet, veuillez indiquer la source lors de la réimpression.
En cas d'infraction, veuillez [email protected] Supprimer.
laisse moi dire quelques mots