亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

單擊按鈕獲取表行的內容

單擊按鈕獲取表行的內容

慕沐林林 2019-12-09 14:14:32
我需要提取表中每列的詳細信息。例如,列“名稱/編號”。該表包含多個地址每行的最后一列都有一個按鈕,使用戶可以選擇列出的地址。問題:我的代碼僅拾取<td>具有類的第一個nr。我該如何工作?這是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});表:<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>
查看完整描述

3 回答

?
慕標琳琳

TA貢獻1830條經驗 獲得超9個贊

您需要更改代碼以找到與單擊的按鈕相關的行。嘗試這個:


$(".use-address").click(function() {

    var id = $(this).closest("tr").find(".nr").text();

    $("#resultas").append(id);

});


查看完整回答
反對 回復 2019-12-09
?
冉冉說

TA貢獻1877條經驗 獲得超1個贊

嘗試這個:


$(".use-address").click(function() {

   $(this).closest('tr').find('td').each(function() {

        var textval = $(this).text(); // this will be the text of each <td>

   });

});

這將找到tr當前單擊的按鈕中最接近的(在DOM中向上移動),然后循環每個按鈕td-您可能要使用值創建一個字符串/數組。


查看完整回答
反對 回復 2019-12-09
  • 3 回答
  • 0 關注
  • 776 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號