使用jquery实现购物车_使用jQuery实现购物车结算功能

更新时间:2021-08-10    来源:jquery    手机版     字体:

【www.bbyears.com--jquery】



  
    
    
    <scripttype="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>
  
  
    您已选购以下商品
  
    
      
        商品名
        单品积分
        市场价
        当当价
        数量
        删除
      
    
    
 
      
        私募(首部披露资本博弈秘密的金融...
        (59折)
        
        删除
      
      
         小团圆(张爱玲最神秘小说遗稿)
        (62折)
        
        删除
      
      
        不抱怨的世界(畅销全球80国的世界...
         (62折)
        
        删除
      
      
        福玛特双桶洗衣机XPB20-07S
         (78折)
        
        删除
      
      
        PHP和MySQL Web开发 (原书第4版)
         (75折)
        
        删除
      
      
        法布尔昆虫记(再买¥68.30即可参加“满199元减10元现金”活动)
         (66折)
        
        删除
      
    
    
      清空购物车
      
        
        
        商品金额总计:
        您共节省金额:¥
可获商品积分:

本文来源:http://www.bbyears.com/wangyezhizuo/135001.html

猜你感兴趣