【问题标题】:Toggle issue with shopping cart jPayPalCart.js切换购物车 jPayPalCart.js 的问题
【发布时间】:2015-02-21 19:16:21
【问题描述】:

我在使用 jPayPalCart.js 切换 myCart div 时遇到了困难。我的购物车运行良好。当我加载页面时,我可以通过单击右上角的购物车来切换购物车。我在 myCart 代码中添加了另一个按钮,显示“关闭”并关闭 myCart div。

但是,当我将商品添加到购物车时,(只有演示页面上的第一项实际添加了商品)单击购物车图标时不再触发此功能。我在浏览器的控制台中没有看到任何错误。

它仅在页面刷新时再次起作用。我怎样才能做到不用刷新页面?

非常感谢有人帮我解决这个问题,这两天让我发疯了。

 $(document).ready(function () {
     $(".menu").activeMenu();
     $("#myCart").hide();

     // Create a basic cart
     $("#myCart").PayPalCart({
         business: 'mypaypal@myemail.com',
         notifyURL: 'http://www.diditwork.com/payment.aspx',
         virtual: false,             //set to true where you are selling virtual items such as downloads
         quantityupdate: true,       //set to false if you want to disable quantity updates in the cart 
         currency: 'CAD',            //set to your trading currency - see PayPal for valid options
         currencysign: '$',          //set the currency symbol
         minicartid: 'minicart',     //element to show the number of items and net value
         persitdays: 0               //set to -1 for cookie-less cart for single page of products, 
         // 0 (default) persits for the session, 
         // x (number of days) the basket will persits between visits
     });

$(".cartImg").click(function () {
    alert("your hitting it");
    $("#myCart").toggle();
});
$(".closeCart").click(function () {
    alert("your hitting it");
    $("#myCart").hide();
});

 });

Demo Site here for example

Reference to script I am using

【问题讨论】:

    标签: javascript html jquery toggle jquery-events


    【解决方案1】:

    仍然环顾四周,我找到了解决方案。通过使用 .live(),修改点击功能,这似乎有效。如果您查看 API 文档,您将看到详细信息,但基本上,购物车正在“动态”更新,这改变了对象的属性。 .live() “刷新”此状态,允许在脚本中识别对象。

    $(".cartImg").live("click", function () {
        alert("your hitting it");
        $("#myCart").toggle();
    });
    $(".closeCart").live("click", function () {
        alert("your hitting it");
        $("#myCart").hide();
    });
    

    【讨论】:

      猜你喜欢
      • 2011-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多