在产品 View 页面中,我想添加一个加号和减号按钮,用于增加和减少产品数量。
最佳答案
前往, 应用\设计\前端\默认\your_theme\模板\目录\产品\ 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>
关于javascript - 如何在数量框中添加增加和减少按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36567460/