jquery 仿购物车的加减数量

it2025-04-21  12

<p>单价:3.95</p> <input id="min" name="" type="button" value="-" /> <input id="text_box" name="" type="text" value="4" /> <input id="add" name="" type="button" value="+" /> <p>总价:<label id="total"></label></p> <script type="text/javascript"> var num=$("#text_box"); $(function(){ $("#add").click(function(){ num.val(parseInt(num.val())+1); //parseInt转来数值型 settotal(); }); $("#min").click(function(){ num.val(parseInt(num.val())-1); settotal(); }); function settotal(){ $("#total").html((parseInt(num.val())*3.95).toFixed(2)); //toFixed 四舍五入保留两位小数位 } }); </script>

 

转载于:https://www.cnblogs.com/vania/p/3319435.html

相关资源:jQuery仿淘宝天猫商品数量加减js代码
最新回复(0)