这是我的代码片段:
<div class="totals">
<table id="shopping-cart-totals-table">
<col />
<col width="1" />
<tfoot>
<tr>
<td style="" class="a-right" colspan="1">
<strong>Grand Total</strong>
</td>
<td style="" class="a-right">
<strong><span class="price">$364.99</span></strong>
</td>
</tr>
</tfoot>
<tbody>
<tr>
<td style="" class="a-right" colspan="1">
Subtotal </td>
<td style="" class="a-right">
<span class="price">$354.99</span> </td>
</tr>
<tr>
<td style="" class="a-right" colspan="1">
Shipping & Handling (Flat Rate - Fixed) </td>
<td style="" class="a-right">
<span class="price">$10.00</span> </td>
</tr>
</tbody>
</table>
我如何使用 jQuery 来选择类“price”的第一个跨度并将该标记中的“$364.99”文本分配给一个变量?
最佳答案
var total = $('.price:first').text();
关于javascript - jQuery 选择器 - 选择特定标签内的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5222361/