在woocommerce购物车页面上,我想添加一个通知,如果你使用数量加按钮,它是达到最大的库存。但是我在购物车上有一个自动更新,所以我必须等到ajax加载完成才能显示通知。我在使用我的脚本时意识到,每次ajax调用后按下的按钮越多,触发的次数就越多,显示通知的次数也会越来越多。怎么处理这个?谢谢。
jQuery( document ).on( 'click', '.plus.button.is-form', function(e) {
var inputval = jQuery(this).closest('div.quantity.buttons_added').find('input[name^="cart"]').val();
var inputmax = jQuery(this).closest('div.quantity.buttons_added').find('input[name^="cart"]').attr('max');
if(inputval==inputmax){
jQuery( document ).ajaxStop( function($) {
alert("TeSZT");
jQuery('.woocommerce-notices-wrapper').html('<div class="woocommerce-info"><div class="woocommerce-info-text">Sajnos ebből a termékből jelenleg nincs több raktáron</div><span class="close-message"></span></div>');
});
}});
发布于 2022-10-28 10:45:14
您可以尝试禁用to元素以防止多次单击。一旦ajaxStop被触发以供以后使用,就启用它。
jQuery( document ).on( 'click', '.plus.button.is-form', function(e) {
var $this = $(this);
$this.prop( "disabled", true );
...
jQuery( document ).ajaxStop( function() {
$this.prop( "disabled", false );
});
...
})https://stackoverflow.com/questions/74234130
复制相似问题