2013-04-29 44 views
1

我在jGrowl中使用Magento 1.7.0.2和jQuery 1.9.1。我试图实现的是获取用户的数量值,然后将其显示为右上角的jGrowl通知。 jGrowl只是使用$ .jGrowl(“My Text Here”)显示文本的一种方式;继承人我得到了什么至今:Magento/jQuery - 在用户点击后获取输入值

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); 
}); 

它的工作原理,但我的notifcation显示3种不同的notifactions是用户类型,如果我在500的数量类型框中,它显示5,50和500单独通知,有没有办法让用户点击输入字段后显示?

在此先感谢

+0

如果您在绑定中使用'keydown',则不需要'change'。 – Kalpesh 2013-04-29 17:48:01

+0

试过了,这次它不显示任何东西。 – Gerardo 2013-04-29 20:36:18

回答

0

我会提供2个版本。你应该你的Javascript绑定到的onclick模糊事件代替的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(wh恩用户点击按钮):

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

值得注意的是,以避免由于原型& jQuery的冲突$的jQuery在Magento使用的最佳实践。确保你也在noConflict() mode中运行jQuery。

+0

这工作真棒(笑)。你从字面上把我从秃头头上拯救出来......不断在我的头发上扯下! – Gerardo 2013-04-30 07:45:12

+0

@Gerardo哈哈很高兴有帮助 – 2013-04-30 13:41:36