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

发布时间 - 2026-01-11 02:47:29    点击率:

本文实例为大家分享了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 


相关栏目: 【 网站优化151355 】 【 网络推广146373 】 【 网络技术251813 】 【 AI营销90571


相关推荐: java ZXing生成二维码及条码实例分享  齐河建站公司:营销型网站建设与SEO优化双核驱动策略  手机网站制作与建设方案,手机网站如何建设?  东莞专业网站制作公司有哪些,东莞招聘网站哪个好?  如何彻底卸载建站之星软件?  香港服务器建站指南:免备案优势与SEO优化技巧全解析  网易LOFTER官网链接 老福特网页版登录地址  如何基于PHP生成高效IDC网络公司建站源码?  Laravel如何处理跨站请求伪造(CSRF)保护_Laravel表单安全机制与令牌校验  Laravel用户密码怎么加密_Laravel Hash门面使用教程  教你用AI将一段旋律扩展成一首完整的曲子  如何在香港免费服务器上快速搭建网站?  百度输入法ai组件怎么删除 百度输入法ai组件移除工具  北京企业网站设计制作公司,北京铁路集团官方网站?  Laravel Telescope怎么调试_使用Laravel Telescope进行应用监控与调试  济南网站建设制作公司,室内设计网站一般都有哪些功能?  大同网页,大同瑞慈医院官网?  Laravel如何保护应用免受CSRF攻击?(原理和示例)  实现点击下箭头变上箭头来回切换的两种方法【推荐】  jQuery 常见小例汇总  电商网站制作多少钱一个,电子商务公司的网站制作费用计入什么科目?  新三国志曹操传主线渭水交兵攻略  Laravel怎么使用Markdown渲染文档_Laravel将Markdown内容转HTML页面展示【实战】  Laravel观察者模式如何使用_Laravel Model Observer配置  Laravel如何从数据库删除数据_Laravel destroy和delete方法区别  html文件怎么打开证书错误_https协议的html打开提示不安全【指南】  Laravel怎么导出Excel文件_Laravel Excel插件使用教程  奇安信“盘古石”团队突破 iOS 26.1 提权  ,交易猫的商品怎么发布到网站上去?  如何彻底删除建站之星生成的Banner?  Laravel Artisan命令怎么自定义_创建自己的Laravel命令行工具完全指南  关于BootStrap modal 在IOS9中不能弹出的解决方法(IOS 9 bootstrap modal ios 9 noticework)  敲碗10年!Mac系列传将迎来「触控与联网」双革新  高性价比服务器租赁——企业级配置与24小时运维服务  详解ASP.NET 生成二维码实例(采用ThoughtWorks.QRCode和QrCode.Net两种方式)  专业商城网站制作公司有哪些,pi商城官网是哪个?  JavaScript数据类型有哪些_如何准确判断一个变量的类型  Laravel如何创建自定义Facades?(详细步骤)  Laravel如何实现多对多模型关联?(Eloquent教程)  Laravel如何配置任务调度?(Cron Job示例)  Laravel如何配置中间件Middleware_Laravel自定义中间件拦截请求与权限校验【步骤】  ChatGPT 4.0官网入口地址 ChatGPT在线体验官网  Gemini手机端怎么发图片_Gemini手机端发图方法【步骤】  Laravel Seeder填充数据教程_Laravel模型工厂Factory使用  如何快速生成可下载的建站源码工具?  Laravel Facade的原理是什么_深入理解Laravel门面及其工作机制  零基础网站服务器架设实战:轻量应用与域名解析配置指南  Laravel Eloquent模型如何创建_Laravel ORM基础之Model创建与使用教程  Laravel如何配置和使用缓存?(Redis代码示例)  Laravel怎么使用Session存储数据_Laravel会话管理与自定义驱动配置【详解】