这次给大家带来jQuery实现购物车添加商品并结算,jQuery实现购物车添加商品并结算的注意事项有哪些,下面就是实战案例,一起来看一下。
<!DOCTYPE html> <html> <head> <metacharset="UTF-8"> <title></title> <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> </head> <body> <pclass="shopping_list_top">您已选购以下商品</p> <pclass="shopping_list_border"> <tablewidth="100%"border="1px solid #ccc"> <trclass="shopping_list_title"> <tdclass="shopping_list_title_1">商品名</td> <tdclass="shopping_list_title_2">单品积分</td> <tdclass="shopping_list_title_3">市场价</td> <tdclass="shopping_list_title_4">当当价</td> <tdclass="shopping_list_title_5">数量</td> <tdclass="shopping_list_title_6">删除</td> </tr> </table> <tablewidth="100%"border="1px solid #ccc"id="myTableProduct"> <trclass="shopping_product_list"id="shoppingProduct_01"> <tdclass="shopping_product_list_1"><ahref="#"rel="external nofollow"rel="external nofollow"rel="external nofollow"rel="external nofollow"rel="external nofollow"rel="external nofollow"class="blue">私募(首部披露资本博弈秘密的金融...</a></td> <tdclass="shopping_product_list_2"><label>189</label></td> <tdclass="shopping_product_list_3">¥<label>32.00</label></td> <tdclass="shopping_product_list_4">¥<label>18.90 </label>(59折)</td> <tdclass="shopping_product_list_5"><inputtype="text"value="1"/></td> <tdclass="shopping_product_list_6"><ahref="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> <trclass="shopping_product_list"id="shoppingProduct_02"> <tdclass="shopping_product_list_1"><ahref="#"rel="external nofollow"rel="external nofollow"rel="external nofollow"rel="external nofollow"rel="external nofollow"rel="external nofollow"class="blue"> 小团圆(张爱玲最神秘小说遗稿)</a></td> <tdclass="shopping_product_list_2"><label>173</label></td> <tdclass="shopping_product_list_3">¥<label>28.00</label></td> <tdclass="shopping_product_list_4">¥<label>17.30</label>(62折)</td> <tdclass="shopping_product_list_5"><inputtype="text"value="1"/></td> <tdclass="shopping_product_list_6"><ahref="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> <trclass="shopping_product_list"id="shoppingProduct_03"> <tdclass="shopping_product_list_1"><ahref="#"rel="external nofollow"rel="external nofollow"rel="external nofollow"rel="external nofollow"rel="external nofollow"rel="external nofollow"class="blue">不抱怨的世界(畅销全球80国的世界...</a></td> <tdclass="shopping_product_list_2"><label>154</label></td> <tdclass="shopping_product_list_3">¥<label>24.80</label></td> <tdclass="shopping_product_list_4">¥<label>15.40</label> (62折)</td> <tdclass="shopping_product_list_5"><inputtype="text"value="2"/></td> <tdclass="shopping_product_list_6"><ahref="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> <trclass="shopping_product_list"id="shoppingProduct_04"> <tdclass="shopping_product_list_1"><ahref="#"rel="external nofollow"rel="external nofollow"rel="external nofollow"rel="external nofollow"rel="external nofollow"rel="external nofollow"class="blue">福玛特双桶洗衣机XPB20-07S</a></td> <tdclass="shopping_product_list_2"><label>358</label></td> <tdclass="shopping_product_list_3">¥<label>458.00</label></td> <tdclass="shopping_product_list_4">¥<label>358.00</label> (78折)</td> <tdclass="shopping_product_list_5"><inputtype="text"value="1"/></td> <tdclass="shopping_product_list_6"><ahref="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> <trclass="shopping_product_list"id="shoppingProduct_05"> <tdclass="shopping_product_list_1"><ahref="#"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> <tdclass="shopping_product_list_2"><label>712</label></td> <tdclass="shopping_product_list_3">¥<label>95.00</label></td> <tdclass="shopping_product_list_4">¥<label>71.20</label> (75折)</td> <tdclass="shopping_product_list_5"><inputtype="text"value="1"/></td> <tdclass="shopping_product_list_6"><ahref="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> <trclass="shopping_product_list"id="shoppingProduct_06"> <tdclass="shopping_product_list_1"><ahref="#"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> <tdclass="shopping_product_list_2"><label>10</label></td> <tdclass="shopping_product_list_3">¥<label>198.00</label></td> <tdclass="shopping_product_list_4">¥<label>130.70</label> (66折)</td> <tdclass="shopping_product_list_5"><inputtype="text"value="1"/></td> <tdclass="shopping_product_list_6"><ahref="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> <pclass="shopping_list_end"> <p><aid="removeAllProduct"href="javascript:void(0);"rel="external nofollow">清空购物车</a></p> <ul> <liclass="shopping_list_end_1"><inputname=""type="image"src="images/shopping_balance.gif"/></li> <liclass="shopping_list_end_2">¥<labelid="product_total"></label></li> <liclass="shopping_list_end_3">商品金额总计:</li> <liclass="shopping_list_end_4">您共节省金额:¥<labelclass="shopping_list_end_yellow"id="product_save"></label><br/> 可获商品积分:<labelclass="shopping_list_end_yellow"id="product_integral"></label> </li> </ul> </p> </p> </body> </html>
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
以上是jQuery实现购物车添加商品并结算的详细内容。更多信息请关注PHP中文网其他相关文章!

我使用您的日常技术工具构建了功能性的多租户SaaS应用程序(一个Edtech应用程序),您可以做同样的事情。 首先,什么是多租户SaaS应用程序? 多租户SaaS应用程序可让您从唱歌中为多个客户提供服务

本文展示了与许可证确保的后端的前端集成,并使用Next.js构建功能性Edtech SaaS应用程序。 前端获取用户权限以控制UI的可见性并确保API要求遵守角色库

JavaScript是现代Web开发的核心语言,因其多样性和灵活性而广泛应用。1)前端开发:通过DOM操作和现代框架(如React、Vue.js、Angular)构建动态网页和单页面应用。2)服务器端开发:Node.js利用非阻塞I/O模型处理高并发和实时应用。3)移动和桌面应用开发:通过ReactNative和Electron实现跨平台开发,提高开发效率。

JavaScript的最新趋势包括TypeScript的崛起、现代框架和库的流行以及WebAssembly的应用。未来前景涵盖更强大的类型系统、服务器端JavaScript的发展、人工智能和机器学习的扩展以及物联网和边缘计算的潜力。

JavaScript是现代Web开发的基石,它的主要功能包括事件驱动编程、动态内容生成和异步编程。1)事件驱动编程允许网页根据用户操作动态变化。2)动态内容生成使得页面内容可以根据条件调整。3)异步编程确保用户界面不被阻塞。JavaScript广泛应用于网页交互、单页面应用和服务器端开发,极大地提升了用户体验和跨平台开发的灵活性。

Python更适合数据科学和机器学习,JavaScript更适合前端和全栈开发。 1.Python以简洁语法和丰富库生态着称,适用于数据分析和Web开发。 2.JavaScript是前端开发核心,Node.js支持服务器端编程,适用于全栈开发。

JavaScript不需要安装,因为它已内置于现代浏览器中。你只需文本编辑器和浏览器即可开始使用。1)在浏览器环境中,通过标签嵌入HTML文件中运行。2)在Node.js环境中,下载并安装Node.js后,通过命令行运行JavaScript文件。

如何在Quartz中提前发送任务通知在使用Quartz定时器进行任务调度时,任务的执行时间是由cron表达式设定的。现�...


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。