0

我有 div 如下

<li>
  <a data-id="'.$row_p[0].'" data-name="'.$row_p[3].'" data-summary="'.$row_p[3].'" data-price="'.$row_p[6].'" data-quantity="1" data-image="'.$row_p[12].'" class="add-cart">
  <span class="icon flaticon-shopping66 "></span>
  </a>
</li>

单击add-cart以下函数调用时(它是一个现成的插件,可以很容易地显示购物车。

    $('.add-cart').myCart({
          classCartIcon: 'my-cart-icon',
          classCartBadge: 'my-cart-badge',
          classProductQuantity: 'my-product-quantity',
          classProductRemove: 'my-product-remove',
          classCheckoutCart: 'my-cart-checkout',
          affixCartIcon: true,
          showCheckoutModal: true,
          clickOnAddToCart: function($addTocart){
            goToCartIcon($addTocart);
          },
          clickOnCartIcon: function($cartIcon, products, totalPrice, totalQuantity) {
            console.log("cart icon clicked", $cartIcon, products, totalPrice, totalQuantity);
          },
          checkoutCart: function(products, totalPrice, totalQuantity) {
            console.log("checking out", products, totalPrice, totalQuantity);
          },
          getDiscountPrice: function(products, totalPrice, totalQuantity) {
            console.log("calculating discount", products, totalPrice, totalQuantity);
            return totalPrice;
          }
        });
But Now the problem is i am using load more jquery Which Load Data On Scroll `$(window).scroll(function()..`  So on scroll i am showing Div As Following

    $.ajax({
        url: 'ajax-load-subcat.php',
        type: 'post',
        data: {row:row,idsubcat:idsubcat},
        beforeSend: function() {
          $("#dataload").show();
        },
        success: function(response){
          $(".post:last").after(response).show().fadeIn("fast");
          $("#dataload").hide();
        }
    });

因此,附加 Dive 后,该add-cart功能也将关闭。表示它没有响应。那么当我滚动并加载数据时如何重新启动我的购物车。

我已经搜索了很多。但他们没有解决我的问题。谢谢你。

4

1 回答 1

0

ajax 成功后尝试再次初始化 add-class/add-cart 函数

$.ajax({
    url: 'ajax-load-subcat.php',
    type: 'post',
    data: {row:row,idsubcat:idsubcat},
    beforeSend: function() {
      $("#dataload").show();
    },
    success: function(response){
      $(".post:last").after(response).show().fadeIn("fast");
      $("#dataload").hide();
      //Re-intiallize Function
      $('.add-cart').myCart({
         ....
      });
    }
});
于 2018-04-28T13:22:25.533 回答