Pobierz zawartość wiersza tabeli za pomocą kliknięcia przycisku
Muszę wyodrębnić szczegóły każdej kolumny w mojej tabeli. Na przykład kolumna „Nazwa / Nr.”.
Tabela zawiera kilka adresówOstatnia kolumna każdego wiersza ma przycisk, który pozwala użytkownikowi wybrać podany adres.Problem: Mój kod odbiera tylko pierwszy<td>
który ma klasęnr
. Jak to działa?
Oto bit jQuery:
$(".use-address").click(function() {
var id = $("#choose-address-table").find(".nr:first").text();
$("#resultas").append(id); // Testing: append the contents of the td to a div
});
Stół:
<table id="choose-address-table" class="ui-widget ui-widget-content">
<thead>
<tr class="ui-widget-header ">
<th>Name/Nr.</th>
<th>Street</th>
<th>Town</th>
<th>Postcode</th>
<th>Country</th>
<th>Options</th>
</tr>
</thead>
<tbody>
<tr>
<td class="nr"><span>50</span>
</td>
<td>Some Street 1</td>
<td>Leeds</td>
<td>L0 0XX</td>
<td>United Kingdom</td>
<td>
<button type="button" class="use-address" />
</td>
</tr>
<tr>
<td class="nr">49</td>
<td>Some Street 2</td>
<td>Lancaster</td>
<td>L0 0XX</td>
<td>United Kingdom</td>
<td>
<button type="button" class="use-address" />
</td>
</tr>
</tbody>
</table>