我试图从表中提取数据,更具体地说,是从列中的类中提取数据。
value = jQuery(this).closest('td').prev('td').prev('td').text();
在这个单元中,有两个类。
一个叫做:
.amount
另一个叫:
.currency
我要瞄准那个叫的。数量。
我试过遵循代码,但它给了我金额和货币。
value = jQuery(this).closest('td').prev('td').prev('td').find('.amount').text();
我做错什么了?
JQuery
jQuery('input').on('click', function() {
if (jQuery(this).is(':checked')) {
productName = jQuery(this).closest('td').prev('td').text();
value = jQuery(this).closest('td').prev('td').prev('td.amount').text();
jQuery(".spiseseddel ul").append('<li>' + productName + value + '</li>');
} else {
productName = jQuery(this).closest('td').prev('td').text();
jQuery('.spiseseddel ul li').filter(function() {
return jQuery.text([this]) === productName;
}).remove();
}
})
HTML
<tr>
<td>
<span class="amount">25,00
<span class="currency">DKK</span>
</span>
</td>
<td class="col-name">product name
</td>
<td class="add-to-cart">
<input type="checkbox">
</td>
</tr>