[英]How to add a increase and decrease button to quantity box
在产品视图页面中,我想添加一个加号和减号按钮,以增加和减少产品数量。
转到app \\ design \\ frontend \\ default \\ your_theme \\ template \\ catalog \\ product \\ view \\ addtocart.phml
在第32行附近搜索,
<label for="qty"><?php echo $this->__('Qty:') ?></label> <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
将以上内容替换为
<div> <label for="qty"><?php echo $this->__('Qty:') ?></label> <input class="button-arrow button-up" type="button" value='+'></input> <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" /> <input class="button-arrow button-down" type="button" value='-'></input> </div>
在.phtml文件粘贴的末尾,
<script type="text/javascript"> //<![CDATA[ jQuery(function($) { $('.add-to-cart .button-up').click(function() { $qty = $(this).parent().find('.qty'); qty = parseInt($qty.val()) + 1; $qty.val(qty); }); $('.add-to-cart .button-down').click(function() { $qty = $(this).parent().find('.qty'); qty = parseInt($qty.val()) - 1; if (qty < 0) qty = 0; $qty.val(qty); }); }); //]]> </script>
使用HTML5输入类型“数字”
在启用之前,请检查所有浏览器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.