【问题标题】:How to add plus + and minus - button in quantity box of product listing page (list.phtml)如何在产品列表页面的数量框中添加加号和减号按钮(list.phtml)
【发布时间】:2016-01-27 10:24:14
【问题描述】:

下面是我的代码,

<?php if($_product->isSaleable()): ?>
<script type="text/javascript">
function setQty(id, url) {
    var qty = document.getElementById('qty_' + id).value;
    document.getElementById('cart_button_' + id).innerHTML = '<button type="button" class="button" onclick="setLocation(\'' + url + 'qty/' + qty + '/\')"><span><span>Add to Cart</span></span></button>';   
}
</script>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty_<?php echo $_product->getId(); ?>" id="qty_<?php echo $_product->getId(); ?>" maxlength="12" value="1" onkeyup="setQty(<?php echo $_product->getId(); ?>, '<?php echo $this->getAddToCartUrl($_product) ?>');" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<span id="cart_button_<?php echo $_product->getId(); ?>"><button type="button" class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span>  
<?php else: ?>

上面的代码我替换为以前的代码(下面的代码)

<?php if($_product->isSaleable()): ?>
<button type="button" class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php else: ?>

现在它正在将数量添加到购物车中,但我必须手动放入盒子中,我想添加 + 和 - 按钮来增加和减少数量,我应该怎么做。 我尝试了很多东西,但在这里不起作用。

【问题讨论】:

标签: php zend-framework magento-1.9


【解决方案1】:

如果没有任何空间设计要求,那么您可以尝试输入类型“数字”而不是“文本”,输入框中带有该字段的增加和减少按钮。

http://www.w3schools.com/html/tryit.asp?filename=tryhtml_input_number

<input type="number" name="qty_<?php echo $_product->getId(); ?>" id="qty_<?php echo $_product->getId(); ?>" maxlength="12" value="1" onkeyup="setQty(<?php echo $_product->getId(); ?>, '<?php echo $this->getAddToCartUrl($_product) ?>');" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-25
    • 2020-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-25
    • 1970-01-01
    相关资源
    最近更新 更多