全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

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

本文实例为大家分享了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">
    <table width="100%" border="1px solid #ccc" >
      <tr class="shopping_list_title" >
        <td class="shopping_list_title_1">商品名</td>
        <td class="shopping_list_title_2">单品积分</td>
        <td class="shopping_list_title_3">市场价</td>
        <td class="shopping_list_title_4">当当价</td>
        <td class="shopping_list_title_5">数量</td>
        <td class="shopping_list_title_6">删除</td>
      </tr>
    </table>
    <table width="100%" border="1px solid #ccc" id="myTableProduct">

      <tr class="shopping_product_list" id="shoppingProduct_01">
        <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">私募(首部披露资本博弈秘密的金融...</a></td>
        <td class="shopping_product_list_2"><label>189</label></td>
        <td class="shopping_product_list_3">¥<label>32.00</label></td>
        <td class="shopping_product_list_4">¥<label>18.90 </label>(59折)</td>
        <td class="shopping_product_list_5"><input type="text" value="1"/></td>
        <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">删除</a></td>
      </tr>
      <tr class="shopping_product_list" id="shoppingProduct_02">
        <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue"> 小团圆(张爱玲最神秘小说遗稿)</a></td>
        <td class="shopping_product_list_2"><label>173</label></td>
        <td class="shopping_product_list_3">¥<label>28.00</label></td>
        <td class="shopping_product_list_4">¥<label>17.30</label>(62折)</td>
        <td class="shopping_product_list_5"><input type="text" value="1"/></td>
        <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">删除</a></td>
      </tr>
      <tr class="shopping_product_list" id="shoppingProduct_03">
        <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">不抱怨的世界(畅销全球80国的世界...</a></td>
        <td class="shopping_product_list_2"><label>154</label></td>
        <td class="shopping_product_list_3">¥<label>24.80</label></td>
        <td class="shopping_product_list_4">¥<label>15.40</label> (62折)</td>
        <td class="shopping_product_list_5"><input type="text" value="2"/></td>
        <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">删除</a></td>
      </tr>
      <tr class="shopping_product_list" id="shoppingProduct_04">
        <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">福玛特双桶洗衣机XPB20-07S</a></td>
        <td class="shopping_product_list_2"><label>358</label></td>
        <td class="shopping_product_list_3">¥<label>458.00</label></td>
        <td class="shopping_product_list_4">¥<label>358.00</label> (78折)</td>
        <td class="shopping_product_list_5"><input type="text" value="1"/></td>
        <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">删除</a></td>
      </tr>
      <tr class="shopping_product_list" id="shoppingProduct_05">
        <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">PHP和MySQL Web开发 (原书第4版)</a></td>
        <td class="shopping_product_list_2"><label>712</label></td>
        <td class="shopping_product_list_3">¥<label>95.00</label></td>
        <td class="shopping_product_list_4">¥<label>71.20</label> (75折)</td>
        <td class="shopping_product_list_5"><input type="text" value="1"/></td>
        <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">删除</a></td>
      </tr>
      <tr class="shopping_product_list" id="shoppingProduct_06">
        <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">法布尔昆虫记</a>(再买¥68.30即可参加“满199元减10元现金”活动)</td>
        <td class="shopping_product_list_2"><label>10</label></td>
        <td class="shopping_product_list_3">¥<label>198.00</label></td>
        <td class="shopping_product_list_4">¥<label>130.70</label> (66折)</td>
        <td class="shopping_product_list_5"><input type="text" value="1"/></td>
        <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">删除</a></td>
      </tr>
    </table>
    <div class="shopping_list_end">
      <div><a id="removeAllProduct" href="javascript:void(0);" rel="external nofollow" >清空购物车</a></div>
      <ul>
        <li class="shopping_list_end_1"><input name="" type="image" src="images/shopping_balance.gif"/></li>
        <li class="shopping_list_end_2">¥<label id="product_total"></label></li>
        <li class="shopping_list_end_3">商品金额总计:</li>
        <li class="shopping_list_end_4">您共节省金额:¥<label class="shopping_list_end_yellow" id="product_save"></label><br/>
          可获商品积分:<label class="shopping_list_end_yellow" id="product_integral"></label>
        </li>
      </ul>
    </div>
  </div>
  </body>
</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


# jQuery  # 购物车  # jQuery实现购物车多物品数量的加减+总价计算  # jQuery实现加入购物车飞入动画效果  # 基于JQuery实现的类似购物商城的购物车  # JQuery实现的购物车功能(可以减少或者添加商品并自动计算价格)  # 纯jquery实现模仿淘宝购物车结算  # jQuery实现购物车计算价格功能的方法  # jQuery实现购物车数字加减效果  # jQuery实现类似淘宝购物车全选状态示例  # jQuery+HTML5加入购物车代码分享  # jQuery仿天猫实现超炫的加入购物车  # 文本框  # 两位  # 大家分享  # 具体内容  # 首部  # 大家多多  # 清空  # 再买  # 原书  # 单品  # 私募  # 当当价  # 中数  # 当鼠标  # 法布尔  # 昆虫记  # parseInt  # price  # parseFloat 


相关文章: 如何零成本快速生成个人自助网站?  建站中国官网:模板定制+SEO优化+建站流程一站式指南  北京营销型网站制作公司,可以用python做一个营销推广网站吗?  佛山网站制作系统,佛山企业变更地址网上办理步骤?  天河区网站制作公司,广州天河区如何办理身份证?需要什么资料有预约的网站吗?  C#怎么创建控制台应用 C# Console App项目创建方法  c# F# 的 MailboxProcessor 和 C# 的 Actor 模型  高防服务器租用指南:配置选择与快速部署攻略  完全自定义免费建站平台:主题模板在线生成一站式服务  唐山网站制作公司有哪些,唐山找工作哪个网站最靠谱?  建站之星如何助力企业快速打造五合一网站?  建站与域名管理如何高效结合?  建站之星代理费用多少?最新价格详情介绍  小建面朝正北,A点实际方位是否存在偏差?  岳西云建站教程与模板下载_一站式快速建站系统操作指南  如何确保西部建站助手FTP传输的安全性?  制作网站的基本流程,设计网站的软件是什么?  教学网站制作软件,学习*后期制作的网站有哪些?  高端云建站费用究竟需要多少预算?  如何通过NAT技术实现内网高效建站?  建站之星如何快速解决建站难题?  专业型网站制作公司有哪些,我设计专业的,谁给推荐几个设计师兼职类的网站?  如何在香港免费服务器上快速搭建网站?  西安专业网站制作公司有哪些,陕西省建行官方网站?  网站制作的步骤包括,正确网址格式怎么写?  长沙企业网站制作哪家好,长沙水业集团官方网站?  如何在Windows虚拟主机上快速搭建网站?  C#如何使用XPathNavigator高效查询XML  胶州企业网站制作公司,青岛石头网络科技有限公司怎么样?  如何选择高效响应式自助建站源码系统?  建站之星代理如何优化在线客服效率?  再谈Python中的字符串与字符编码(推荐)  如何在万网自助建站平台快速创建网站?  定制建站流程解析:需求评估与SEO优化功能开发指南  如何配置FTP站点权限与安全设置?  如何在宝塔面板中修改默认建站目录?  制作网站的过程怎么写,用凡科建站如何制作自己的网站?  建站主机SSH密钥生成步骤及常见问题解答?  制作企业网站建设方案,怎样建设一个公司网站?  如何正确选择百度移动适配建站域名?  如何快速使用云服务器搭建个人网站?  如何自定义建站之星模板颜色并下载新样式?  已有域名建站全流程解析:网站搭建步骤与建站工具选择  宁波自助建站系统如何快速打造专业企业网站?  代刷网站制作软件,别人代刷火车票靠谱吗?  宝华建站服务条款解析:五站合一功能与SEO优化设置指南  建站主机核心功能解析:服务器选择与网站搭建流程指南  手机怎么制作网站教程步骤,手机怎么做自己的网页链接?  建站主机选购指南:核心配置与性价比推荐解析  ,在苏州找工作,上哪个网站比较好? 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。