当当网上书店购物车——JS源码
2023-09-14 08:57:41 时间
$(function($){ //根据您挑选的商品,当当为您推荐部分的显示和隐藏 $("#shopping_commend_arrow").click(function(){ if($("#shopping_commend_sort").css("display")=="none"){ $(this).attr("src","images/shopping_arrow_up.gif"); }else{ $(this).attr("src","images/shopping_arrow_down.gif"); } $("#shopping_commend_sort").toggle(); }); //商品隔行变色 $("#myTableProduct").find("tr:odd").css("backgroundColor","#ffebcd"); //商品变色 $("#myTableProduct").find("tr").mouseover(function(){ $(this).css("backgroundColor","#fff"); }).mouseout(function(){ if($("#myTableProduct").find("tr").index($(this))%2==1) {//判断是否奇数行 $(this).css("backgroundColor","#ffebcd"); }else{ $(this).css("backgroundColor","#fefbf2"); } }); //计算总价 function totalPrice(){ var percents= 0,prePrices= 0,prices=0;//积分,原价,现价 $("#myTableProduct").find("tr").each(function(i,ele){ var num=$(ele).find(".shopping_product_list_5").find("input").val();//数量 percents+=parseInt($(ele).find(".shopping_product_list_2").text())*num; //解决下js中浮点数的bug问题,因此建议浮点数的运算不要放在前台,这里是指粗略的解决了一下 var price=parseInt($(ele).find(".shopping_product_list_4").find("label").text().replace(".",""))*num; prices+=price; var prePrice=parseInt($(ele).find(".shopping_product_list_3").find("label").text().replace(".",""))*num; prePrices+=prePrice; }); $("#product_integral").text(percents); $("#product_total").text(prices/100); $("#product_save").text((prePrices-prices)/100); return prices/100; } totalPrice(); //删除商品 $("#myTableProduct").find(".shopping_product_list_6").children("a").click(function(){ if(confirm("您确定要删除商品么?")){ $(this).parent().parent().remove(); totalPrice(); } }); //修改数量 $("#myTableProduct").find(".shopping_product_list_5").children("input").change(function(){ var value=$(this).val(); if((value == "")||!(/^[0-9]*[1-9][0-9]*$/.test(value))){ alert("数量不能为空,且只能为正整数"); $(this).val(1); } var t =totalPrice(); alert("修改成功!,您的商品总金额是"+t+"元"); }); //清空购物车 $("#removeAllProduct").click(function(){ //注意清除的先后顺序 $("#myTableProduct").next().remove(); $("#myTableProduct").remove(); $(".shopping_list_border").append("<div class='empty_product'><div>您还没有挑选商品,<a href='index.html'>去挑选看看>></a></div></div>"); }); });
相关文章
- jQuery分页插件(jquery.page.js)的使用
- JS框架_(JQuery.js)绚丽的3D星空动画
- JS框架_(coolShow.js)图片旋转动画特效
- JS框架_(Typed.js)彩色霓虹灯发光文字动画
- JS框架_(Vue.js)带有星期日期的数字时钟
- 【nodejs原理&源码赏析(6)】深度剖析cluster模块源码与node.js多进程
- baguetteBox.js响应式画廊插件(纯JS)
- Node.js自定义对象事件监听与发射
- 发现一段灰产JS代码
- 当当网上书店头部和尾部——JS源码
- 当当网上书店头部和尾部——JS源码
- 07_js走路小游戏
- [JS Pattern] Mixin Pattern
- js 执行上下文
- [Node.js] Mock an API for Local Development in React with Mirage JS
- [Nuxt] Update Vuex State with Mutations and MapMutations in Vue.js
- 让Visual Studio 也支持JS代码折叠 —— 续 [ Visual Studio | Js | ScriptOutline | SmallOutline ]
- Underscore.js 1.3.3 源码分析收藏
- JS对象类型的确定
- UI5应用clone到webIDE后,如何处理无法加载sap-ui-core.js的错误
- Atitit.跨语言 java c#.net php js常用的codec encode算法api 兼容性 应该内置到语言里面
- js 浏览器兼容css中webkit、Moz、O、ms...写法封装(es6语法)
- js之选项卡效果(淘宝侧边栏)
- JS,Jquery获取各种屏幕的宽度和高度
- Sencha Ext JS 7.4.0.39 Crack
- Node.js学习笔记——fs模块