此功能相当于购物车加减功能:
<p class="_stepper"> <input class="stepper_input" data-bind="value:orderInfo.PrintNumber,event:{ change: GetPrintNumber}" type="number" id="printNumber" value="1"/> <input type="button" class="up" data-bind="click:numAdd" value="加" /> <input type="button" class="down" data-bind="click:numDec" value="减" /> </p>个
//stepper //+1 function numAdd() { var num_add = parseInt($("#quantity").val()) + 1; if ($("#quantity").val() == "") { num_add = 1; } $("#quantity").val(num_add); var total = parseFloat($("#price").val()) * parseInt($("#quantity").val()); $("#totalPrice").html(total.toFixed(2)); } //-1 function numDec() { var num_dec = parseInt($("#quantity").val()) - 1; if (num_dec < 1) { alert("不能小于1"); } else { $("#quantity").val(num_dec); } }
效果
时间: 2024-11-09 21:26:00