这是我用来在CART页面中用ajax更新购物车的代码-
jQuery('div.woocommerce').on('change keyup mouseup', 'input.qty', function(){ // keyup and mouseup for Firefox support
if (timeout != undefined) clearTimeout(timeout); //cancel previously scheduled event
if (jQuery(this).val() == '') return; //qty empty, instead of removing item from cart, do nothing
timeout = setTimeout(function() {
jQuery('[name="update_cart"]').trigger('click');
}, 1000 );
});
它工作正常,但是我的问题是,当我在商店页面中尝试相同的代码时,它没有更新我的购物车- 这是我尝试过的-
jQuery('li.product').on('change keyup mouseup', 'input.qty', function(){ // keyup and mouseup for Firefox support
if (timeout != undefined) clearTimeout(timeout); //cancel previously scheduled event
if (jQuery(this).val() == '') return; //qty empty, instead of removing item from cart, do nothing
timeout = setTimeout(function() {
jQuery('[name="update_cart"]').trigger('click');
}, 1000 );
});
如果您要检查(https://cdn.royalancer.co.uk/test/),这是链接。
答案 0 :(得分:0)
您可以这样使用
jQuery('li.product').on('change keyup mouseup', 'button.plus.qib-button,button.minus.qib-button', function(){ // keyup and mouseup for Firefox support
var timeout;
var this_ = jQuery(this);
timeout = setTimeout(function() {
this_.parent().parent().find('.ajax_add_to_cart').trigger( 'click' );
clearTimeout(timeout);
}, 1000 );
});