jquery购物车实时结算特效实现思路 |
本文标签:购物车,实时结算 复制代码 代码如下: $(function(){ $(".child_tab tr:last-child").find("td").css({borderBottom:none}) //获得文本框对象 var t = $(".amount-input"); //数量增加操作 $(".amount-up").click(function(e){ var c1=parseInt($(this).prev().val()); $(this).prev().val(c1+1); e.preventDefault() setTotal(); }); //数量减少操作 $(".amount-down").click(function(e){ var c1=parseInt($(this).next().val()); if(c1>=1){ $(this).next().val(c1-1); }; e.preventDefault() setTotal(); }); function setTotal(){ //取每个条件的值 var num1=$(".sum1").text(); var num2=$(".sum2").text(); var num3=$(".sum3").text(); var total=0; var x1=4,x2=10,x3=49; //遍历合计件数 t.each(function(index,ele){ total+=parseInt($(ele).val()); }); $(".figure").html(total); //判断个数满足哪个要求 if(total<x2){ b2=num1 }else if(total>=x2&&total<=x3){ b2=num2 }else if(total>=x3){ b2=num3 } $(".money").html((total*b2).toFixed(2)+元);//toFixed()是保留小数点的函数很实用哦 } //初始化 setTotal(); }) |