Javascript 使用购物车jPayPalCart.js切换问题
我在使用jPayPalCart.js切换myCart div时遇到困难。我的购物车运行正常。当我加载页面时,我可以通过点击右上角的购物车来切换购物车。我在myCart代码中添加了另一个按钮,上面写着“关闭”并关闭myCart div 但是,当我向购物车添加项目时,(只有演示页面上的第一个项目实际添加了项目),当单击购物车图标时,此功能不再触发。我在浏览器的控制台中没有看到任何错误 只有当页面刷新时,它才会再次工作。我怎样才能不刷新页面呢 如果有人帮我解决这个问题,我会非常感激的,这两天我都快疯了Javascript 使用购物车jPayPalCart.js切换问题,javascript,jquery,html,javascript-events,toggle,Javascript,Jquery,Html,Javascript Events,Toggle,我在使用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();
});
});
我仍然环顾四周,终于找到了解决办法。通过使用.live(),修改click函数,这似乎是可行的。如果您查看API文档,您将看到详细信息,但基本上,购物车正在“动态”更新,这改变了对象的属性。live()“刷新”此状态,允许在脚本中识别对象
$(".cartImg").live("click", function () {
alert("your hitting it");
$("#myCart").toggle();
});
$(".closeCart").live("click", function () {
alert("your hitting it");
$("#myCart").hide();
});