javascript - 如何在数量框中添加增加和减少按钮

标签 javascript php magento product

在产品 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"> //&lt;![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); }); }); //]]&gt; </script>

关于javascript - 如何在数量框中添加增加和减少按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36567460/

相关文章:

javascript - SDK2 : checkboxes in a RallyGrid column?

php - MySQL - 计算天前

javascript - HTML Canvas 中的 2D 图形和统一缩放

javascript - 如何通过匹配文本来选择下拉选项?

扩展 IMagick 类的 PHP 怪异

seo - 如何强制magento使用完整的产品路径?

magento - 将 magento apis 用于电子商务网站

php - Magento 复制 Controller 到本地

javascript - ReSharper 智能感知指向错误的函数

PHP/MySQL - 散列到 BIGINT 以确保不重复