Appending "you save" below and adding the two costs in jQuery
<tr><td class="summaryitem"><a href="javascript:OpenRebatesWindow('/shop/Phones/PhonePricingRebates.aspx?action=devicepromo&device=60c0ca0d-b68d-4edd-b667-0d4320b60ede');"&开发者_Python百科gt;Instant discount</a></td><td class="summaryprice">-$200.00</td></tr>
<tr class="last"><td class="summaryitem"><a href="javascript:OpenRebatesWindow('/shop/Phones/PhonePricingRebates.aspx?action=devicepromo&device=60c0ca0d-b68d-4edd-b667-0d4320b60ede');">Web-only discount</a></td><td class="summaryprice">-$79.99</td></tr>
How to Append "you save" below the table and adding the two costs $200+$79.99) in jQuery.
var sum = 0;
$(".summaryprice").each(function(){
sum += getSum(this.html()); // I'm not sure this or $(this) try both
});
function getSum(ammountString){
var t = ammountString.split('-$');
return parseFloat(t[1]);
}
var prices = $(".summaryPrice").map(function() {
return parseFloat($(this).text().replace("-$", ""));
}).get();
for(var sum = 0, i = prices.length; i; sum += prices[--i]);
$("#theTable").after("<p>You save " + sum + "</p>");
Demo.
精彩评论