我非常需要帮助 我有一张桌子,我需要从行中获得两个span标签 复选框已被选中并使其成为变量
这里是表格,我需要的是.downpayment和.fullpay,但仅限于检查的行
如果它有帮助,那么该表的屏幕上限有助于理解
<table class="table">
<tr class="planbreak">
<td rowspan="2"> <input type="checkbox" name="plan"> </td>
<td colspan="3" class="plan-title">Premium Add - Stated</td>
<td colspan="2" class="plan-right"><span class="badge"><a href="#" data-toggle="modal" data-target="#modifiyvehicle">T & C</a></span> 60/125000</td>
</tr>
<tr class="plan-info">
<td>10% Down: $<span class="downpayment">262.00</span></td>
<td class="text-center">18 Months: $131.15</td>
<td class="text-center">12 Months: $196.73</td>
<td class="text-center">Full Pay: $<span class="fullpay">2,623.00</span></td>
<td class="text-right">Coverage miles: 15,000 (yr)</td>
</tr>
<tr class="planbreak">
<td rowspan="2"> <input type="checkbox" name="plan" > </td>
<td colspan="3" class="plan-title">Premium Add - Stated</td>
<td colspan="2" class="plan-right"><span class="badge"><a href="#" data-toggle="modal" data-target="#modifiyvehicle">T & C</a></span> 60/100000</td>
</tr>
<tr class="plan-info">
<td>10% Down: $<span class="downpayment">262.00</span></td>
<td class="text-center">18 Months: $131.15</td>
<td class="text-center">12 Months: $196.73</td>
<td class="text-center">Full Pay: $<span class="fullpay">2,623.00</span></td>
<td class="text-right">Coverage miles: 15,000 (yr)</td>
</tr>
</table>
我试过这个
downpay = $(this).closest('tr').next().next('span').text();
但不起作用
downpay = $(this).closest('tr').next().find('span').text();
这只返回所有类
答案 0 :(得分:3)
您的第二次尝试几乎是正确的,只需将该类添加到span
选择器:
downpay = $(this).closest('tr').next().find('span.downpayment').text();
答案 1 :(得分:0)
您可以使用:
var downpay = $(this).closest('tr').next().find('span.downpayment').text();
获取.downpayment
文字和:
var fullpay = $(this).closest('tr').next().find('span.fullpay').text();
获取.fullpay
文字
答案 2 :(得分:0)
var this_row = $(this).parents('tr'),//Get the selected row
downpay = this_row.next().find('span.downpayment').text(),//.downpayment text
fullpay = this_row.next().find('span.fullpay').text();//.fullpay text