如何在产品列表页面(list.phtml)的数量框中添加加+和减号-按钮


How to add plus + and minus - button in quantity box of product listing page (list.phtml)

下面是我的代码,

<?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: ?>

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

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

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" />