Magento产品页面的数量“+”或“ - ”

时间:2016-08-26 06:06:14

标签: javascript jquery magento-1.9

我正在使用Magento 1.9.1,尝试在产品页面上添加数量“+”和“ - ”按钮。按钮显示在页面上,但数量增量和描述不能完美运行。

这是我的“ addtocart.phtml

<?php $buttonTitle = $this->__('Buy'); ?>
<?php if($_product->isSaleable()): ?>

    <div class="add-to-box">
    <label class="required-deatials"><?php echo 'Price:';?> </label><?php echo $this->getPriceHtml($_product) ?>
     <?php if(!$_product->isGrouped()): ?>

            <div class="qty-wrapper">
            <label for="qty"><?php echo $this->__('Qty:') ?></label>

               <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo  $this->getMinimalQty($_product) ?>" title="<?php echo $this->__('Qty') ?>"  class="input-text qty"/>

                <div class="nb-qty-wrap">
                <div id="up1" class="up">
                    <input type="button" onclick="var qty_el = document.getElementById('qty'); var qty = qty_el.value; if( !isNaN( qty ) &amp;&amp; qty &gt; 0 ) qty_el.value--;return false;" class="dn" />
                </div>
                <div id="dn1" class="dn"> 
                    <input type="button" onclick="var qty_el = document.getElementById('qty'); var qty = qty_el.value; if( !isNaN( qty )) qty_el.value++;return false;" class="up" />
                </div>  
                </div>
                </div>
        <?php endif; ?>
        <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>

        <?php echo $this->getChildHtml('', true, true) ?>
    </div>
<?php endif; ?>

和javascript用于

    <script type ="text/javascript">
jQuery("div.qty-wrapper").append('<input type="button" id="up1" class="up" />').prepend('<input type="button" id="dn1" class="dn" />');
    jQuery(".up").click(function()
    {
        var currentVal = parseInt(jQuery(this).prev(".qty").val());

        if (!currentVal || currentVal=="" || currentVal == "NaN") currentVal = 0;

        jQuery(this).prev(".qty").val(currentVal + 1);
    });

    jQuery(".dn").click(function()
    {
        var currentVal = parseInt(jQuery(this).next(".qty").val());
        if (currentVal == "NaN") currentVal = 0;
        if (currentVal > 0)
        {
            jQuery(this).next(".qty").val(currentVal - 1);
        }
    });
    </script>

当我从主题中移除样式类,即<div class="nb-qty-wrap">时,脚本工作正常。如果我添加模板的样式,它就无法正常工作。

0 个答案:

没有答案
相关问题