本文实例为大家分享了jQuery实现购物车结算功能展示的具体代码,供大家参考,具体内容如下
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery-1.8.3.js" ></script>
<script>
/*删除*/
$(function(){
$(".blue").bind("click",function(){
$(this).parent().parent().remove();
totalPrice();
}); /*当鼠标离开文本框时,获取当前值,调用totalPrice()函数进行结算*/
$(".shopping_product_list_5 input").bind("blur",function(){
var t = $(this).val();
totalPrice();
});
var allPrice = 0;
var allReduce = 0;
var allCount = 0;
$("#myTableProduct tr").each(function(){ /*循环购物车列表的每一行*/
var num = parseInt($(this).find(".shopping_product_list_5 input").val()); /*获取文本框中数量值*/
var price = parseFloat($(this).find(".shopping_product_list_4 label").text()); /* 获取商品价格*/
var total = price * num;
allPrice += total; /*计算所有商品的总价格*/
/*获取节省的金额*/
var reduce = parseFloat($(this).find(".shopping_product_list_3 label").text()) - parseFloat($(this).find(".shopping_product_list_4 label").text());
var reducePrice = reduce*num;
allReduce +=reducePrice;
/*获取积分*/
var count = parseFloat($(this).find(".shopping_product_list_2 label").text());
allCount +=count;
});
$("#product_total").text(allPrice.toFixed(2)); /*填写计算结果,其中利用toFixed()函数保留两位小数*/
$("#product_save").text(allReduce.toFixed(2));
$("#product_integral").text(allCount.toFixed(2));
});
function totalPrice(){
var allPrice = 0;
var allReduce = 0;
var allCount = 0;
$("#myTableProduct tr").each(function(){
var num = parseInt($(this).find(".shopping_product_list_5 input").val());
var price = parseFloat($(this).find(".shopping_product_list_4 label").text());
var total = price * num;
allPrice += total;
var reduce = parseFloat($(this).find(".shopping_product_list_3 label").text()) - parseFloat($(this).find(".shopping_product_list_4 label").text());
var reducePrice = reduce*num;
allReduce +=reducePrice;
var count = parseFloat($(this).find(".shopping_product_list_2 label").text());
allCount +=count;
});
$("#product_total").text(allPrice.toFixed(2));
$("#product_save").text(allReduce.toFixed(2));
$("#product_integral").text(allCount.toFixed(2));
}
</script>
</head>
<body>
<div class="shopping_list_top">您已选购以下商品</div>
<div class="shopping_list_border">










