1

我将 Magento 1.7.0.2 和 jQuery 1.9.1 与 jGrowl 一起使用。我试图实现的是获取用户的数量值,然后将其显示为右上角的 jGrowl 通知。jGrowl 只是一种使用 $.jGrowl("My Text Here"); 显示文本的方式;这是我到目前为止得到的:

HTML

    <div class="add-to-cart bottom">

    <input type="text" name="qty" id="qty" maxlength="12" value="500" title="Qty" onclick="$.jGrowl('500 Added To Cart');" class="input-text qty">
            <button type="button" title="Add to Cart" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span>Continue to cart</span></span></button>
        </div>

jQuery

    $('input#qty.input-text.qty').bind("keydown change", function(event){
    $.jGrowl(this.value);
});

它可以工作,但我的通知显示 3 个不同的通知是用户类型,如果我在数量框中输入 500,它会显示 5、50,然后在单独的通知中显示 500,有没有办法让它在用户点击后显示输入字段?

提前致谢

4

1 回答 1

0

我将提供 2 个版本。您应该将 Javascript 绑定到onclickblur事件而不是 keydown:

HTML:

<div class="add-to-cart bottom">
    <input type="text" name="qty" id="qty" maxlength="12" value="500" title="Qty" class="input-text qty">
    <button type="button" title="Add to Cart" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span>Continue to cart</span></span>
    </button>
</div>

jQuery(当用户从​​输入框中聚焦时):

jQuery('.add-to-cart.bottom .input-text').blur(function(){
    jQuery.jGrowl(jQuery(this).val());
});

或者

jQuery(当用户单击按钮时):

jQuery('.add-to-cart.bottom .btn-cart').click(function(){
    jQuery.jGrowl(jQuery('.add-to-cart.bottom .qty').val());
});

请注意,由于原型和 jQuery 冲突,最好避免在 Magento 中将 $ 用于 jQuery。确保你也在noConflict()模式下运行 jQuery 。

于 2013-04-29T23:12:23.613 回答