我正在尝试获取我的购物车的小计(要访问购物车,您必须从tecnosport.es点击屏幕右上角)。
要获取小计:
jQuery(".elementor-menu-cart__subtotal > .woocommerce-Price-amount > bdi");
由于我有三个小部件,所以我得到了三个元素,但您可以看到这样的值;
jQuery(".elementor-menu-cart__subtotal > .woocommerce-Price-amount > bdi").text();
我的目标:
当我添加一些产品到购物车时,我想听听小计是否发生了变化(例如,通过console.log在控制台中查看它)。
我试过了,但没用:
1.
由于我得到了三个元素,我应该在循环中迭代它们并侦听事件:
jQuery(".elementor-menu-cart__subtotal > .woocommerce-Price-amount > bdi").bind("DOMSubtreeModified", function(){
jQuery(this).each(function( index ) {
console.log("The content changed");
});
});
2.
我试图更改顺序:
jQuery(".elementor-menu-cart__subtotal > .woocommerce-Price-amount > bdi").each(function( index ) {
jQuery(this).bind("DOMSubtreeModified", function(){
console.log("The content changed");
});
});
有一件奇怪的事:
例如,如果我使用某个ID为的单个元素(而不是三个元素)来执行此操作,则它可以完美地工作。我重复错了吗?我很失落。